Codice per effettuare il binding fra radio button ed un enumeratore
C#
public class EnumBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
if (System.Enum.IsDefined(value.GetType(), value) == false)
return DependencyProperty.UnsetValue;
object parameterValue = System.Enum.Parse(value.GetType(), parameterString);
return parameterValue.Equals(value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
return System.Enum.Parse(targetType, parameterString);
}
}
|
XAML
IsChecked="{Binding Enumeratore, Converter={StaticResource EnumBooleanConverter}, ConverterParameter=Valore,UpdateSourceTrigger=PropertyChanged}"/>
|
Nessun commento:
Posta un commento