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

    这样就能正确更新了。
  • 相关阅读:
    str_replace
    [转载][HTML] 普通的DIV分层以及版透明效果
    [PHP] PHP Excel导出 以及编码问题
    [FreeProxy]FreeProxy代理服务器端软件介绍 之 sock 5
    修改MySQL的递增的起始值
    台哥原创:java五子棋源码(人机对弈)
    java游戏开发杂谈
    java游戏开发杂谈
    java游戏开发杂谈
    java游戏开发杂谈
  • 原文地址:https://www.cnblogs.com/fresky/p/2624629.html
Copyright © 2011-2022 走看看