gpt4 book ai didi

wpf - 检查后更改单选按钮的图像

转载 作者:行者123 更新时间:2023-12-03 10:58:16 25 4
gpt4 key购买 nike

<StackPanel Name="StpAddDel" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
<RadioButton Name="rdbactive" GroupName="actinact" VerticalAlignment="Center" Margin="5,0" Width="50" Height="15" Foreground="Blue">
<RadioButton.Style>
<Style TargetType="{x:Type RadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<Image Source="c:\image.png" Width="32" Height="32"/>
<ContentPresenter/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</RadioButton.Style>
</RadioButton>
<RadioButton Name="rdbinactive" GroupName="actinact" VerticalAlignment="Center" Margin="5,0" Width="60" Height="15" Foreground="Blue">
<RadioButton.Style>
<Style TargetType="{x:Type RadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<Image Source="c:\image.png" Width="32" Height="32"/>
<ContentPresenter/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</RadioButton.Style>
</RadioButton>
<Button Name="BtnAdd" Height="20" Width="20" Margin="5,0" Template="{StaticResource AddImgBtnTemplate}" />
<Button Name="BtnDel" Height="20" Width="20" Margin="5,0" Template="{StaticResource DelImgBtnTemplate}" />
</StackPanel>

在上面的代码中,我有2个单选按钮,我在单选按钮上放置了图像,我的要求是我想在选中后更改单选按钮的图像,请为此提供帮助...

最佳答案

您可以为此使用ControlTemplate.Triggers

<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<Image x:Name="PART_Image" Source="c:\image.png" Width="32" Height="32"/>
<ContentPresenter/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="PART_Image" Property="Source" Value="new source"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

Image命名,并在 Source为true时更改该控件的 IsChecked属性

编辑

如果您还想在鼠标悬停时“突出显示”,则可以添加 DropShadowEffect和另一个 Trigger,这一次是 IsMouseOver为true时
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="PART_Image" Property="Effect">
<Setter.Value>
<DropShadowEffect ShadowDepth="0" Color="Yellow" Opacity="0.5"/>
</Setter.Value>
</Setter>
</Trigger>

关于wpf - 检查后更改单选按钮的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30987136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com