Dav*_*ave 2 c# wpf radio-button mvvm-light
我有一组正确显示的单选按钮(如下图所示)。现在,当我点击它们时,它们周围似乎出现了一个红色方块(如下图 2 所示)。这让我想起了 wpf 的渲染问题,因为我之前看到的与 winforms 类似。
至于开发,我使用 wpf 和 c#,mvvmlight。
另外 iv 在下面包含了我的代码:
<RadioButton GroupName="Part_GrpPlayBtn"
ToolTip="Play"
Style="{StaticResource StyleRadioButton}"
Template="{StaticResource Template_Play}"
IsChecked="{Binding PlayState, Converter={StaticResource PlayStateToCheckedConvert}, ConverterParameter={x:Static local:ePlaybackState.ePlay}}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked" >
<i:InvokeCommandAction Command="{Binding PlayCommand,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:VMSPlayBarControl}}}" >
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<Style TargetType="RadioButton" x:Key="StyleRadioButton" >
<Setter Property="Margin" Value="5" />
<Setter Property="ToolTipService.IsEnabled" Value="{Binding IsChecked, RelativeSource={RelativeSource Self}}"/>
</Style>
<ControlTemplate x:Key="Template_Play" TargetType="{x:Type RadioButton}">
<Grid>
<Ellipse x:Name="Part_BgEllipse" Style="{StaticResource StyleEllipse}" />
<Image x:Name="PART_Image" Source="{StaticResource ImgPlayOff}" Style="{StaticResource StyleImage}"/>
<ContentPresenter/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Part_BgEllipse" Property="Fill" Value="{StaticResource PrimaryBlueColorBrush}" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="PART_Image" Property="Source" Value="{StaticResource ImgPlayHover}"/>
<Setter TargetName="Part_BgEllipse" Property="Fill" Value="{StaticResource SecondaryLightGrayColorBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
关于上述问题的任何建议或想法?
谢谢。
这是由于绑定问题引起的。您将单选按钮的 IsChecked 属性绑定到 ViewModel 属性,作为转换器中ConvertBack函数中的某些不正确的数据类型。也请发布您的转换器代码。
无论如何尝试这个并检查它是否有效。
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
751 次 |
| 最近记录: |