2025-04-24 20:56:44 +08:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
|
2026-02-21 16:31:24 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.RevitAddins.Common.Converters;
|
2025-04-24 20:56:44 +08:00
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|