Home Forums WPF controls Xceed Toolkit Plus for WPF How to apply MetroDarkTheme to StyleableWindow

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • GuglielmoCancelli
    Participant
    Post count: 19
    #43700 |

    Hi,
    we would like to apply MetroDarkTheme to the StyleableWindow from code-behind, as suggested in a LiveExplorer, more or less like this:

    private void StyleableWindow_Loaded(object sender, RoutedEventArgs e)
    {
    Resources.MergedDictionaries.Clear();
    Resources.MergedDictionaries.Add(new ToolkitMetroDarkThemeResourceDictionary());
    }
    The method is attached to the xaml via loaded method:
    Loaded=”StyleableWindow_Loaded”

    We are using full licenced 3.0 version.
    Unfortunately, something is missing and the theme is not applied.
    Any hints?

    Best wishes,
    Guglielmo

    Fawzi [Xceed]
    Member
    Post count: 722

    Hi,

    When you do this in the StyleableWindow_Loaded callback :
    Resources.MergedDictionaries.Clear();
    Resources.MergedDictionaries.Add(new ToolkitMetroDarkThemeResourceDictionary());

    you say that all children of the StyleableWindow will have the Toolkit Metro theme applied. But not the StyleableWindow itself. It needs to be set higher in the hierarchy, like in Application.Current.

    What you can do to apply the Toolkit Metro theme to this specific StyleableWindow is set the StyleableWindow style, right after adding the ToolkitMetroDarkThemeResourceDictionary :

    this.Style = new Style(typeof(StyleableWindow), this.Resources[“MetroStyleableWindow”] as Style);

    This line will try to find a style for StyleableWindow named “MetroStyleableWindow” in the resources, and apply it to the StyleableWindow you have.

    We have created a case so that in v3.1 you could use this line instead:

    this.Style = new Style(typeof(StyleableWindow), this.Resources[ this.DefaultStyleKey ] as Style);

    GuglielmoCancelli
    Participant
    Post count: 19

    Thank you Fawzi,
    that worked like a charm!

    Diane [Xceed]
    Moderator
    Post count: 1353

    The fix for this issue was included in the latest version.

    “In the StyleableWindow, an implicit style for StyleableWindowKey is now defined.”

    Download Link: http://forums.xceed.com/latest-xceed-toolkit-plus-for-wpf

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.