C# 当且仅当满足某些先决条件时,是否可以启动转换器?

C# 当且仅当满足某些先决条件时,是否可以启动转换器?,c#,wpf,converters,C#,Wpf,Converters,我有一组单选按钮,它们都连接到viewmodel中的同一个变量 <RadioButton Content="20" Margin="5,0" GroupName="open_rb" IsChecked="{Binding Path=mOpen.Threshold, Mode=OneWayToSource, Converter={StaticResource RadioBoolToIntConverter}, ConverterParameter=20, UpdateSourceTrigg

我有一组单选按钮,它们都连接到viewmodel中的同一个变量

<RadioButton Content="20" Margin="5,0" GroupName="open_rb" 
IsChecked="{Binding Path=mOpen.Threshold, Mode=OneWayToSource, Converter={StaticResource RadioBoolToIntConverter}, ConverterParameter=20, UpdateSourceTrigger=PropertyChanged}" />

<RadioButton Content="50" Margin="5,0" GroupName="open_rb"
  IsChecked="{Binding Path=mOpen.Threshold, Mode=OneWayToSource, Converter={StaticResource RadioBoolToIntConverter}, ConverterParameter=50, UpdateSourceTrigger=PropertyChanged}"/>

<RadioButton Content="70" Margin="5,0" GroupName="open_rb"
 IsChecked="{Binding Path=mOpen.Threshold, Mode=OneWayToSource, Converter={StaticResource RadioBoolToIntConverter}, ConverterParameter=70, UpdateSourceTrigger=PropertyChanged}"/>
基本上,这个想法是,如果单击某个单选按钮,转换器将传递20、30或70(取决于单击哪个单选按钮)到mOpen.Threshold,这是一个无符号int

现在,如果选中或未选中单选按钮,将触发单选按钮“isChecked”事件,值为true和false。现在,如果它为false,我将从转换器返回一个空字符串,它不会解析为uint,并导致UI抱怨


如果选中单选按钮,是否只能使用此转换器?这意味着对于这个组,如果我点击一个单选按钮,这个转换器应该只触发一次,而不是两次

使用这种方法,似乎您只想在选中任何
属性时设置源属性
属性设置为
true
。然后,当
val
false
时,可以返回
Binding.DoNothing

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
    //bool to int (if bool is true then pass this val)
    bool val = (bool)value;
    if (val == true)
        return UInt32.Parse(parameter as string);

    return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
    //bool to int (if bool is true then pass this val)
    bool val = (bool)value;
    if (val == true)
        return UInt32.Parse(parameter as string);

    return Binding.DoNothing;
}