none
Generic.xaml not able to be seen by the WPF designer in a Winforms application RRS feed

  • Question

  • :) first post on this forum. I'm used to Stackoverflow. Sorry if i break any of the etiquette  of this forum. So to start off I have seen this problem in VS2010, 2012, and 2013 RC. The project I am working on is using .NET3.5. I am fairly new to the WPF world, but have fallen in love with it. I'm finally to the point where it takes me less time to make a nice looking Window in WPF then it would take me building a "quick" Winforms Form. Because of that when I have taken it upon my self to replace the winforms forms in a project to a WPF Window. This is a bit of a sore spot with me currently. It almost makes me want to create a new WPF project then move all the code over to this new project. In this case though that is not a viable option. So on to the problem at hand. What I did is in my winforms project is I created a new folder called WPF and put added a WPF UserControl in it. I then switched the UserControl to a Window. (I'm not thrilled that I have to do that, wish I could just add the Window) After replicating the Form I'm replacing I decide to use a static resource for my buttons. So after hours of searching I finally figured out how to make my Winforms application even see my Themes/Generic.xaml file. Problem that I am experiancing is that my designer still can't see it. Which means in order for me to see what my change to any of the resources does to my application I either have to run my program and look at all the windows, or I have to have a test WPF project open (or blend) and see what it would like from there. So how can I make my designer see the resource file too?

    Changes I've added to my Winforms project is this (thus far)

    AssemblyInfo.cs

    [assembly: ThemeInfo(
        ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
        //(used if a resource is not found in the page, 
        // or application resource dictionaries)
        ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
        //(used if a resource is not found in the page, 
        // app, or any theme specific resource dictionaries)
    )]

    Program.cs

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                InstantiateProgram();
    
                EnsureApplicationResources();
    
                System.Windows.Forms.Application.Run(main);
            }
            public static void EnsureApplicationResources()
            {
                if (System.Windows.Application.Current == null)
                {
                    // create the Application object
                    new System.Windows.Application();
                    System.Windows.Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
                    // merge in your application resources
                    System.Windows.Application.Current.Resources.MergedDictionaries.Add(
                        System.Windows.Application.LoadComponent(
                            new Uri("/Themes/Generic.xaml",
                            UriKind.Relative)) as ResourceDictionary);
                }
            }
            private static void InstantiateProgram()
            {
                System.Windows.Forms.Application.EnableVisualStyles();
                System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
                main = new frmMain();
            }

    I think that I have seen somewhere hinting that I should add a App.xaml. Something about that feels wrong though. Is there another setting somewhere that I can make my designer see my resource file?

    Sunday, September 22, 2013 2:17 AM

Answers

  • Hi immeraufdemhund,

    I think that is impossible. To make the style change applied on design time, we have to let the designer know where to load the resource and designer can parse the xaml. But the fact is no because it is winform designer.

    Any changes you made to the generic.xaml only can be refelected by xaml designer.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by immeraufdemhund Thursday, September 26, 2013 12:16 AM
    Wednesday, September 25, 2013 7:10 AM

All replies

  • Hi immeraufdemhund,

      Welcome to MSDN Forum Support.

      I am trying to involve someone familiar with this topic to further look at this issue.  I'll involve some others on your issue.

      Sincerely,

      Jason Wang


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 2:54 AM
    Moderator
  • Hi immeraufdemhund,

    I think that is impossible. To make the style change applied on design time, we have to let the designer know where to load the resource and designer can parse the xaml. But the fact is no because it is winform designer.

    Any changes you made to the generic.xaml only can be refelected by xaml designer.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    Alan Yao
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by immeraufdemhund Thursday, September 26, 2013 12:16 AM
    Wednesday, September 25, 2013 7:10 AM