【问题标题】:Red square appears around radio button control when clicked in Wpf在 Wpf 中单击时,单选按钮控件周围出现红色方块
【发布时间】:2016-10-14 05:53:26
【问题描述】:

我有一组正确显示的单选按钮(如下图所示)。 现在,当我单击它们时,它们周围似乎出现了一个红色方块(如下图第二张所示)。 这让我想起了 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>

对上述问题有什么建议或想法吗?

谢谢。

【问题讨论】:

    标签: c# wpf radio-button mvvm-light


    【解决方案1】:

    这是由于绑定问题引起的。 您将单选按钮的 IsChecked 属性绑定到 ViewModel 属性,作为转换器中 ConvertBack 函数中的一些不正确的数据类型。也请发布您的转换器代码。

    不管怎样,试试这个,看看它是否有效。

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return Binding.DoNothing;
    }
    

    【讨论】:

    • 您的建议似乎已经解决了这个问题。似乎 ii 正在返回 value 参数,而不是像您自己提到的那样返回 Binding.DoNothing 。谢谢。
    猜你喜欢
    • 2020-09-16
    • 2011-12-10
    • 2019-12-03
    • 2020-12-15
    • 2020-10-03
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 2013-05-08
    相关资源
    最近更新 更多