2011-08-01 31 views
10

Đây là App.xaml:Tại sao không thiết lập kiểu nền của công việc nền cửa sổ?

<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> 

Tôi cũng có MainWindow.xaml. Khi được xem trong chế độ Thiết kế trong VS, nền của nó là, thực sự, màu xám, như nó phải được. Dù sao, khi ứng dụng đang chạy, nền của cửa sổ là màu trắng mặc định.

Tại sao?

Cách sửa lỗi này? Tôi muốn tất cả các cửa sổ có nền chuẩn theo mặc định.

Trả lời

11

Theo dõi trên câu trả lời từ CodeNaked, bạn sẽ phải tạo một Style cho mỗi Window bạn có, nhưng bạn có thể sử dụng phong cách tương tự cho tất cả chúng với BasedOn như thế này

<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

Cảm ơn! Ngay cả