WPF RadioButton 绑定boolean值

xml 复制代码
<RadioButton
    Margin="5"
    Content="替换"
    IsChecked="{Binding CorrectionOption.ReCorrectionMode}" />
<RadioButton
    Margin="5"
    Content="平均"
    IsChecked="{Binding CorrectionOption.ReCorrectionMode, Converter={StaticResource ReCorrectionModeToBooleanConverter}}" />

切记:RadioButton 不能有GroupName属性

csharp 复制代码
public class ReCorrectionModeToBooleanConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is bool booleanValue)
        {
            return !booleanValue; // 取反
        }
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is bool booleanValue)
        {
            return !booleanValue; // 取反
        }
        return value;
    }
}
相关推荐
...62213 分钟前
WinForm中Socket通信服务端客户端代码实现讲解
tcp/ip·c#·socket
gis开发之家3 小时前
Spring Boot 4 定时任务与异步线程池:从 @Scheduled 到高并发任务编排(生产级实战)
java·spring boot·后端·wpf·spring boot4
唐青枫17 小时前
别只会看日志:C#.NET SOS 调试扩展从 Dump 到内存泄漏排查
c#·.net
yswenli1 天前
基于C#开发网站视频嗅探下载工具——BrowserVideoGrabber
c#·videodownload·webvideodownload·videograbber
Lost of 程序猿1 天前
M2 实战:询价与采购订单聚合落地——跨聚合一致性、领域事件与 Outbox
开发语言·c#·asp.net·.net
Polevne1 天前
C# GRPC 一元与双向流
linux·算法·c#
clz13145211 天前
如何设计一个优雅可靠的金融级联机接口
wpf
闲云自留地2 天前
云平台存储管理员:Cinder 创建挂载卷 + Swift 分布式存储原理
分布式·wpf·swift
XiaoZhenHua982 天前
C#工业机器视觉Recipe配方系统设计:多型号、多相机、多工位参数如何统一管理
c#·软件架构·机器视觉·工业自动化·工业软件·recipe
fujisheng6612 天前
FUI 导航实践:拆开 Layer、History、Coverage 与 Cache 的组合语义
c#·unity3d