zoukankan      html  css  js  c++  java
  • WPF Radio组的绑定

    都是控件编,RadioButtion 简单绑定使用,model.cs下边定义属性

    private int _isSuccess;

    public int IsSuccess { get { return _isSuccess; } set { _isSuccess = value; } }

    打开 Window1.xaml.cs 文档,model.cs 绑定你的 DataContext, 返回 xaml 绑定 RadioButton 控件:

    <RadioButton IsChecked="{Binding Path=IsSuccess, Converter={StaticResource radioBoolToIntConverter}, ConverterParameter=1}" Content="one" />

    <RadioButton IsChecked="{Binding Path=IsSuccess, Converter={StaticResource radioBoolToIntConverter}, ConverterParameter=2}" Content="two" />

    <RadioButton IsChecked="{Binding Path=IsSuccess, Converter={StaticResource radioBoolToIntConverter}, ConverterParameter=3}" Content="three" />

    主要属性是Converter和ConverterParameter,Converter是个转换器,使用动态资源中一个Converter类,就是RadioBoolToIntConverter类,ConverterParameter是传递到RadioBoolToIntConverter类参数实现对比

    以下是转换器,RadioBoolToIntConverter.cs:

    public class RadioBoolToIntConverter : IValueConverter

    {

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

    int integer = (int)value;

    if (integer==int.Parse(parameter.ToString()))

    return true;

    else

    return false;

    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

    {

    return parameter;

    }

    }

    添加名命空间

    xmlns:local="clr-namespace:名命空间"

    添加资源

    <Window.Resources>

    <local:RadioBoolToIntConverter x:Key="radioBoolToIntConverter" />

    </Window.Resources>

    很简单就绑定在一样。

  • 相关阅读:
    第十讲:网络虚拟化(二)
    第九讲:网络虚拟化(一)
    第十二讲:存储虚拟化(二)
    第十一讲:存储虚拟化(一)
    第八讲:I/O虚拟化
    第七讲:内存虚拟化
    第六讲:CPU虚拟化
    node to traverse cannot be null!
    利用 squid 反向代理提高网站性能(转载)
    Servlet自动加载
  • 原文地址:https://www.cnblogs.com/lizeyan/p/3583864.html
Copyright © 2011-2022 走看看