当前位置: 首页 > article >正文

WPF RadioButton 绑定boolean值

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

切记:RadioButton 不能有GroupName属性

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;
    }
}

http://www.kler.cn/news/330469.html

相关文章:

  • EasyExcel全面实战:掌握多样化的Excel导出能力
  • 华为OD机试 - 分班问题(Java 2024 E卷 200分)
  • 国庆节快乐前端(HTML+CSS+JavaScript+BootStrap.min.css)
  • 3.点位管理改造-列表查询——帝可得管理系统
  • (undone) 阅读 MapReduce 论文笔记
  • 联合体/共同体与结构体的区别
  • SpringBoot 请求和响应
  • Python库pandas之四
  • Java进销存ERP管理系统源码
  • 如何评估和部署 IT 运维系统?
  • React常见面试题目
  • ubuntu查看端口开放状态
  • npm切换到淘宝镜像
  • 智能教室云平台管理系统:基于Spring Boot、WebSocket与传感器的设计方案
  • 小红书AI配音神器:3秒变声百种风格
  • Redis的基本使用
  • 旅游推荐|旅游推荐系统|基于Springboot+VUE的旅游推荐系统设计与实现(源码+数据库+文档)
  • Go实现RabbitMQ 死信队列、优化
  • 《重生到现代之从零开始的C语言生活》—— 字符函数和字符串函数
  • 数据结构双向链表和循环链表