35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
|
|
namespace Cowain.Bake.Common.Converter
|
|
{
|
|
public class RadioButtonToIndexConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
// 将 RadioButton 的值与 ViewModel 中的值进行比较并返回是否匹配
|
|
if (value == null || parameter == null)
|
|
return false;
|
|
|
|
return value.ToString() == parameter.ToString();
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
// 这个转换通常不需要,可以简单地返回 DependencyProperty.UnsetValue
|
|
if ((bool)value)
|
|
{
|
|
return parameter;
|
|
}
|
|
return DependencyProperty.UnsetValue;
|
|
}
|
|
}
|
|
}
|