Why a window style couldn't apply to WPF windows automatically without x:Key property RRS feed

  • Question

  • I got this style in App.xaml

    <Style TargetType="{x:Type Window}">
    --the style code--

    In this case, any window wouldn't use this style but the default style of current system.

    When I change that like this

    <Style x:key="MyWindowStyle" TargetType="{x:Type Window}">
    --the style code--

    And, use Style="{DynamicResource MyWindowStyle}" in the xaml of my window, the window could use the customized style. So, I need write Style="{DynamicResource MyWindowStyle}" for all my windows.

    The strange point is: other elements like button could use the customized style without x:Key property. It seems that only window couldn't.

    Is WPF just designed in this way...or...there's something wrong with my code or settings or other things...

    Thanks for help.

    • Edited by iamyae Monday, December 8, 2014 1:46 PM
    Monday, December 8, 2014 1:24 PM


All replies