2017-03-23 8 views
1

Xamlのウィンドウでスタイルを適用しようとしました。しかし、私のコードはスタイルを適用していません。誰もがこの問題で私を助けることができますか?Xamlのウィンドウでスタイルを適用する方法

<Window x:Class="Shweta.Window5" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="Window5" Height="300" Width="300"> 

    <Window.Resources> 
     <Style TargetType="{x:Type Window}"> 
      <Setter Property="FontFamily" Value="Verdana"></Setter> 
      <Setter Property="Foreground" Value="LightBlue"></Setter> 
      <Setter Property="FontWeight" Value="Normal"></Setter> 
      <Setter Property="WindowStyle" Value="None"></Setter> 
      <Setter Property="Background" Value="LightBlue"></Setter> 
     </Style> 
    </Window.Resources> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="40*" /> 
      <ColumnDefinition Width="238*" /> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="47*" /> 
      <RowDefinition Height="214*" /> 
     </Grid.RowDefinitions> 

     <Grid Grid.Column="1"> 
      <Button Margin="0,0,114,16" Content="shweta"/> 
     </Grid> 
    </Grid> 
</Window> 

答えて

0

あなたがApp.xamlのResourcesであなたのスタイルを配置する必要があります。

<Application.Resources> 
    <Style TargetType="{x:Type Window}"> 
     <Setter Property="FontFamily" 
       Value="Verdana"></Setter> 
     <Setter Property="Foreground" 
       Value="LightBlue"></Setter> 
     <Setter Property="FontWeight" 
       Value="Normal"></Setter> 
     <Setter Property="WindowStyle" 
       Value="None"></Setter> 
     <Setter Property="Background" 
       Value="LightBlue"></Setter> 
    </Style> 
</Application.Resources> 

、ユーザーが定義した場合、あなたのそれはWindowなくWindow自身の子供たちのためになるだろうWindowStyle

+0

はい、それはすべてにスタイルを適用しましたプロジェクト全体のページ。ありがとう! – shweta

1

代わりに、ウィンドウのResourcesにスタイルを置くこと、あなたが直接ウィンドウのStyleプロパティに割り当てることができます:私は で試してみました、

<Window x:Class="Shweta.Window5" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="Window5" Height="300" Width="300"> 
    <Window.Style> 
     <Style TargetType="{x:Type Window}"> 
      <Setter Property="FontFamily" Value="Verdana"/> 
      <Setter Property="Foreground" Value="LightBlue"/> 
      <Setter Property="FontWeight" Value="Normal"/> 
      <Setter Property="WindowStyle" Value="None"/> 
      <Setter Property="Background" Value="LightBlue"/> 
     </Style> 
    </Window.Style> 
    ... 
</Window> 
関連する問題