【WPF】 问题总结-RaidButton修改样式模板后作用区域的变化

最近工作需要,需要重绘RaidButton控件,具体想要达成的的效果是这样的:

【WPF】 问题总结-RaidButton修改样式模板后作用区域的变化

 

当点击按钮任意一个地方的时候,按钮的背景改变。

于是我是这样对控件模板进行修改的:

<Style x:Key="raidstyle" TargetType="RadioButton"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="RadioButton"> <Grid> <Border x:Name="bord1" Width="320" Height="138" BorderBrush="#6B778D" BorderThickness="1" CornerRadius="8" /> <Border x:Name="bord" <Grid> <StackPanel Margin="0,33,0,0"> <Grid Margin="0,-10,0,10" HorizontalAlignment="Center" VerticalAlignment="Center"> <Ellipse x:Name="ell1" Width="33" Height="33" StrokeThickness="3" Stroke="White" /> <Ellipse x:Name="ell2" Width="13" Height="13" StrokeThickness="1" Stroke="#2196F3" Fill="#2196F3" Visibility="Collapsed" /> </Grid> <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" /> </StackPanel> </Grid> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="bord1" Property="Background" Value="#FF919191" /> <Setter TargetName="bord1" Property="Opacity" Value="0.1" /> <Setter TargetName="ell1" Property="Stroke" Value="#2196F3" /> <Setter TargetName="ell2" Property="Visibility" Value="Visible" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zywfsy.html