1

I'm using Single Application class in my project, i want to create custom Main Method in my application,but i have a problem: I cannot view *.xaml files in my project (page and user controls in visual studio) i get this warning not style and templates working (because my resource file is loading runtime) : warning in all xaml files: The resource "name" could not be resolved.

my custom app.cs file Code:

public partial class App : Application, ISingleInstanceApp
{
    private const string Unique = "Agrin Download Manager";

    [STAThread]
    public static void Main()
    {
        if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
        {
            var application = new App();
            application.InitializeComponent();
            application.Run();

            // Allow single instance code to perform cleanup operations
            SingleInstance<App>.Cleanup();
        }
    }

    private bool _contentLoaded;

    /// <summary>
    /// InitializeComponent
    /// </summary>
    [System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
    public void InitializeComponent()
    {
        if (_contentLoaded)
        {
            return;
        }
        _contentLoaded = true;

        this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
        Assembly a = Assembly.GetExecutingAssembly();
        using (Stream stream = a.GetManifestResourceStream("Agrin.Windows.UI.AppResources.xaml"))
        {
            XmlReader XmlRead = XmlReader.Create(stream);
            Application.Current.Resources =
                (ResourceDictionary)XamlReader.Load(XmlRead);
            XmlRead.Close();
        }
    }
}

and my AppResources.xaml (load runtime from InitializeComponent method):

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Resources/Themes/ControlStyles.xaml"/>
    <ResourceDictionary Source="Resources/Themes/VectorStyles.xaml"/>
    <ResourceDictionary Source="Resources/Themes/Brushes.xaml"/>
    <ResourceDictionary Source="Resources/Themes/LanguageAndFonts.xaml"/>
    <ResourceDictionary Source="Resources/Themes/ColorsResource.xaml"/>
    <ResourceDictionary Source="Resources/Themes/WpfDataGridTheme.xaml"/>
    <!--<ResourceDictionary Source="Theme/PathToBitmapResources.xaml"/>-->
</ResourceDictionary.MergedDictionaries>

please help me to use xaml viewer in visual studio, that AppResources.xaml build action is "Embedded Resource" and load runtime .

2
  • I don't know of what kind of resources you are writing, but for what I know you must be sure that the resources are public in your files to be visible to xaml and also that the resource container has been compiled before the resource cannot be found error disappear.
    – Sabrina_cs
    Sep 25, 2015 at 14:22
  • project works in runtime and no problem, problem is working on visual studio xaml viewer, not load style and templates because my AppResources.xaml is loading in runtime, if i changed build action to ApplicationDefinition visual studio show me error to build because generated appresources.g.cs file and it create always Main method. Sep 25, 2015 at 14:26

1 Answer 1

0

OK, I changed my project AppResources.xaml file to this and works:

<Application 
x:Class="Agrin.Windows.UI.App2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Converters.xaml"/>
            <ResourceDictionary Source="Resources/Themes/ControlStyles.xaml"/>
            <ResourceDictionary Source="Resources/Themes/VectorStyles.xaml"/>
            <ResourceDictionary Source="Resources/Themes/Brushes.xaml"/>
            <ResourceDictionary Source="Resources/Themes/LanguageAndFonts.xaml"/>
            <ResourceDictionary Source="Resources/Themes/ColorsResource.xaml"/>
            <ResourceDictionary Source="Resources/Themes/WpfDataGridTheme.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.