Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[WPF] ネストしたスタイルを定義する (NestedStyles in WPF)
<Window x:Class="NestedStyles.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>
<Style TargetType="{x:Type Button}">
<Setter Property="MinWidth" Value="100" />
</Style>
<Style x:Key="RootStyle" TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="5" />
<Style.Resources>
<Style TargetType="{x:Type StackPanel}">
<Setter Property="Margin" Value="5, 0, 5, 0" />
</Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="MinHeight" Value="50" />
</Style>
</Style.Resources>
</Style>
<Style x:Key="ButtonAreaStyle" TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
<Setter Property="HorizontalAlignment" Value="Right" />
<Style.Resources>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Margin" Value="10, 10, 10, 0" />
<Setter Property="MinHeight" Value="60" />
</Style>
</Style.Resources>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot" Style="{StaticResource RootStyle}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListBox Grid.Column="0" />
<StackPanel Orientation="Vertical" Grid.Column="1">
<Button Content="Refresh" />
</StackPanel>
</Grid>
<StackPanel Style="{StaticResource ButtonAreaStyle}" Grid.Row="1">
<Button Content="Yes" />
<Button Content="No" />
</StackPanel>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment