当前位置:首页 > Windows程序 > 正文

WPF QuickStart系列之样式和模板(Style and Template) Part1

2021-03-27 Windows程序

<Window.Resources> <Style x:Key="RadioButtonStyle01" TargetType="RadioButton"> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Foreground" Value="#565656"/> <Setter Property="Background" Value="#EDEEEF"/> <Setter Property="FontSize" Value="12"/> <Setter Property="FontWeight" Value="Bold"/> <Setter Property="Width" Value="100"/> <Setter Property="Height" Value="45"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="RadioButton"> <Border x:Name="MainBorder" BorderThickness="1" BorderBrush="#8B99BC" CornerRadius="1" Background="#F0F2F2"> <Grid> <Image x:Name="imgChecked" Visibility="Collapsed" Source="/ControlTemplatingDemo;component/Resources/Images/Completed_02.png" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,-8,-10,0"/> <ContentPresenter RecognizesAccessKey="True" Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="MainBorder" Property="Background" Value="#239FFF"/> <Setter TargetName="imgChecked" Property="Visibility" Value="Visible"/> <Setter Property="Foreground" Value="White"/> <Setter TargetName="MainBorder" Property="BorderBrush" Value="#239FFF"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <StackPanel Orientation="Horizontal"> <RadioButton Content="作业练习" IsChecked="True" Margin="10,5,10,0"/> <RadioButton Content="考试测验" Margin="0,5,10,0"/> </StackPanel>

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/68412.html