ChildWindow Style


  • Hi,

    I added the themes toolkit (ShinyRed,...). It's working great except for my childwindow container (window title, close button...) : the container is keeping its standard colors.

    However, i note all the xaml themes include style for childwindow (<Style TargetType="controls:ChildWindow">). 

    In fact, i think it's normal because my theme tag <toolkit:Theme x:Name="ThemeContainer"> is placed inside the ChildWindow. So, how to include style for the window container please ?

    Thank you, Etienne.


    Monday, June 20, 2011 10:57 AM


  • I have posted the tag to include the resourceDictionary, here are few basic tuturials

    Monday, June 20, 2011 10:06 PM

All replies

  • Please help ! Cry

    My ChildWindow content starts with this code :

        <toolkit:Theme x:Name="ThemeContainer" ThemeUri="/MyApp;Component/Themes/ShinyRed.xaml">
            <Grid x:Name="LayoutRoot">

    Then, the grid content appears fine with red controls due to the theme ShinyRed. But the window chrome (title panel and close button) is not red, however the theme includes resources to change it :

        <Style TargetType="controls:ChildWindow">
            <Setter Property="IsTabStop" Value="false"/>

    So, i tried to load the style dynamically when i open the childwindow :

    MyChildWindowClass MyChildWindow = new MyChildWindowClass();
    MyChildWindow.Style = this.Resources["CWStyle"] as Style;

    Where CWStyle is named here :

        <Style TargetType="controls:ChildWindow" x:Key="CWStyle">
            <Setter Property="IsTabStop" Value="false"/>

    But it doesn't work. Have you got an idea please ?

    Monday, June 20, 2011 8:53 PM
  • One way is to set the TargetType and the start tag same mean if you have the TargetType "controls:ChildWindow then your childwindow tag in your form should start controls:ChildWindow. Second way is to set the name/key to the style and then apply that style by using Style={StaticResource childWindowStyle}

    hope that will help.

    Monday, June 20, 2011 9:08 PM
  • is your resourceDictionary which is ShinyRed.xaml is included in app.xaml

    try to use following

    <toolkit:Theme x:Name="ThemeContainer" ThemeUri="/Themes/ShinyRed.xaml">

     <toolkit:Theme x:Name="ThemeContainer" ThemeUri="Themes/ShinyRed.xaml">

    Monday, June 20, 2011 9:10 PM
  • In fact, i found the solution finally, i was almost :

    MyChildWindowClass MyChildWindow = new MyChildWindowClass(); 
    MyChildWindow.Style = this.ThemeContainer.Resources["CWStyle"] as Style; 

    It's this.ThemeContainer.Resources, not this.Resources.

    Thank you for help.


    Monday, June 20, 2011 9:28 PM
  • good to see that you have found solution, in your previous code 

    this.Resources["CWStyle"] as Style;

    statement looks for the resource of the current page /user control that is why it can't find the style. But you can apply the style in the xaml end as well if you are not opening from code behind

    Monday, June 20, 2011 9:33 PM
  • I would like to call the resources from xaml, but it's not working. If you have an example, it should be great Wink

    Monday, June 20, 2011 9:39 PM
  • do you have following tag in you app.xaml ?

        			<ResourceDictionary Source="Themes/ShinyRed.xaml"/>
    if no then add the above tag in your app.xaml file

    Monday, June 20, 2011 9:54 PM
  • are you using dll or you have resource dictionary located in the theme folder ?

    Monday, June 20, 2011 9:55 PM
  • I'm not using dll, i imported the xaml themes in my application directly, and i'm choosing one theme from a combobox.

    So, i don't have the ResourceDirectory mentioned in app.xaml.


    Monday, June 20, 2011 10:03 PM
  • I have posted the tag to include the resourceDictionary, here are few basic tuturials

    Monday, June 20, 2011 10:06 PM
  • Thank you.

    To complete my previous post, this is how i do to load any skin dynamically. It's working great now :

    From the childwindow constructor, i call this :


    and this is the function called :

            public static void GetTheme(object container) //container is UserControl or ChildWindow
                cCommon.cParameters Params = Application.Current.Resources[cCommon.Resources.Params.ToString()] as cCommon.cParameters;
                string Uri = string.Format("/MyApp;Component/Themes/{0}.xaml", Params.Theme);
                System.Windows.Controls.Theming.Theme ThemeContainer = (System.Windows.Controls.Theming.Theme)((FrameworkElement)container).FindName("ThemeContainer");
                System.Uri ThemeUri = new System.Uri(Uri, System.UriKind.Relative);
                ThemeContainer.ThemeUri = ThemeUri;
                if (container is ChildWindow)
                    (container as ChildWindow).Style = ThemeContainer.Resources["CWStyle"] as Style;

    I think it could be intersting for other people.
    Bye, Etienne.

    Monday, June 20, 2011 10:25 PM
  • yes it will definitly help other people as well if they have same type of problem.

    Monday, June 20, 2011 11:37 PM
  • One request if any of my post help you in solving problem then please mark it as answer which is required :)

    Tuesday, June 21, 2011 12:32 AM