2011-08-01 99 views
10

这里是App.xaml中:为什么窗口背景的样式设置不起作用?

<Application> 
<Application.Resources> 
    <ResourceDictionary> 
     <Style TargetType="Window"> 
      <Setter Property="SnapsToDevicePixels" Value="True"/> 
      <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
     </Style> 
    </ResourceDictionary> 
</Application.Resources> 
</Application> 

我也有MainWindow.xaml。在VS中的设计模式下查看时,它的背景确实是灰色的,因为它应该是。无论如何,当应用程序运行时,窗口的背景是默认的白色。

为什么?

如何解决这个问题?我希望所有的窗口默认都有标准的背景。

回答

11

跟进从CodeNaked答案,你必须创建为每Window你有一个Style,但你可以使用相同的样式为所有的人都用BasedOn这样

<Application.Resources> 
    <ResourceDictionary> 
     <Style TargetType="Window"> 
      <Setter Property="SnapsToDevicePixels" Value="True"/> 
      <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
     </Style> 
     <Style TargetType="{x:Type local:MainWindow}" 
       BasedOn="{StaticResource {x:Type Window}}"/> 
     <Style TargetType="{x:Type local:SomeOtherWindow}" 
       BasedOn="{StaticResource {x:Type Window}}"/> 
     <!-- Add more Windows here... --> 
    </ResourceDictionary> 
</Application.Resources 
+0

谢谢!即使