zoukankan      html  css  js  c++  java
  • WPF中radiobutton 的 data binding方法

    WPF中的radiobox通过data binding绑定到一个bool属性后,如下所示,尽管UI可以正确的显示,但是data binding的属性不能正确的更新。比如user点了No之后属性UserChoice还是True。

    <RadioButton Content="Yes" IsChecked="{Binding UserChoice}"/>
    <RadioButton Content="No"/>

    需要用如下的方式:
    <RadioButton Content="Yes" IsChecked="{Binding UserChoice}"/>
    <RadioButton Content="No" IsChecked="{Binding UserChoice, Converter={StaticResource radioConverter}}"/>

    radioconverter如下:
        public class RadioButtonConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value is bool)
                {
                    return !(bool)value;
                }
                return value;
            }

            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value is bool)
                {
                    return !(bool)value;
                }
                return value;
            }
        }

    这样就能正确更新了。
  • 相关阅读:
    Mybatis懒加载
    Mybatis 动态SQL
    Mybatis的多表查询
    linux selinux
    linux find/vi复制粘贴
    01-oracle限定查询-20190404
    awk
    sed
    windows删除指定日期前的文件
    win10 sshsecureshellclient删除profile保存的信息
  • 原文地址:https://www.cnblogs.com/fresky/p/2624629.html
Copyright © 2011-2022 走看看