更新整理
This commit is contained in:
43
ShrlAlgoToolkit.Mvvm/Converters/ComparisonConverter.cs
Normal file
43
ShrlAlgoToolkit.Mvvm/Converters/ComparisonConverter.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ShrlAlgoToolkit.Mvvm.Converters;
|
||||
|
||||
public class ComparisonConverter : IValueConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Model属性->Control属性
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="targetType"></param>
|
||||
/// <param name="parameter"></param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//value:ViewModel属性,枚举/数字/字符串
|
||||
//parameter:ConverterParameter,枚举/数字/字符串
|
||||
//return (string)parameter == (string)value;
|
||||
//绑定的枚举属性与控件转换参数一致则选中
|
||||
return value.Equals(parameter);
|
||||
//return (string)parameter == (string)value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控件选中,将Converter参数传给模型属性
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="targetType"></param>
|
||||
/// <param name="parameter"></param>
|
||||
/// <param name="culture"></param>
|
||||
/// <returns></returns>
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//value:bool 比如RadioButton的check属性
|
||||
//parameter:ConverterParameter枚举
|
||||
//一样才传递给ViewModel
|
||||
//选中则返回枚举类
|
||||
return value is true ? parameter : Binding.DoNothing;
|
||||
//return (bool)value ? parameter : Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user