楽天アフィリエイト

2016年9月26日月曜日

WPF ラジオボタンのスタイル

ラジオボタンのボタン部分などスタイルを変更する際のサンプルコード
<!-- ラジオボタンスタイル設定 --> <Style TargetType="RadioButton" BasedOn="{StaticResource {x:Type RadioButton}}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RadioButton}"> <BulletDecorator Cursor="Hand"> <!-- ラジオボタンコンテンツ全体 --> <Border CornerRadius="3" BorderBrush="#FF909090" BorderThickness="3"> <Grid> <!-- ラジオのチェック部分 --> <Border Width="5" Margin="2" HorizontalAlignment="Left" Background="#FFCDCDCD" CornerRadius="1" Name="RadioMark"/> <!-- ラジオのコンテンツ部分--> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Grid> <!-- ボタンの背景グラデーション設定 --> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="White" Offset="0" /> <GradientStop Color="LightGray" Offset="1" /> </LinearGradientBrush> </Border.Background> </Border> </BulletDecorator> <!-- チェック時のスタイル設定 --> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter TargetName="RadioMark" Property="Background" Value="Red"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>