<Window x:Class="IT_Tutorial4_3.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       Title="MainWindow" Height="350" Width="525">
   <Window.Resources>
       <!--x:Key指定しないと子すべてのターゲットに適用される-->
       <Style TargetType="Button">
           <Setter Property="Width" Value="50"/>
           <Setter Property="Height" Value="50"/>
       </Style>
       <Style x:Key="CustumStyle" TargetType="Button">
           <Setter Property="Width" Value="100"/>
           <Setter Property="Height" Value="100"/>
       </Style>
   </Window.Resources>

   <StackPanel>
       <!--x:Keyによるリソースの指定ありと無しの違いに注目-->
       <Button>abc</Button>
       <Button>def</Button>
       <Button Style="{DynamicResource CustumStyle}">ghi</Button>
       
       <!--内部にstyleを埋め込める。親のリソースで指定した広域適用のスタイルは内部側スタイルが優先され無視される点に注目-->
       <Button Content="jkl">
           <Button.Style>
               <Style TargetType="Button">
                   <Setter Property="Background" Value="BlanchedAlmond"/>
               </Style>
           </Button.Style>
       </Button>

       <Button Background="BlanchedAlmond" Content="こちらはスタイルが適用されBackgroundプロパティも生きる"/>
       
   </StackPanel>
</Window>
最終更新:2012年10月18日 23:15