wpfradio-buttonintegerupdown

Radio buttons binding on specific value without prefix on WPF


I have a window that has two radio buttons, the 2nd has an IntegerUpDown.

The "IsChecked" property is binding to the IntegerUpDown.

I want the IntegerUpDown to have values between 1 and 100, but in case "1" is selected - I want the other radio button to be turned on.

The issue starts when typing, for example, "12". The "1" immediately flicks the radio button without waiting for the other numbers.

My WPF code:

Radio Button 1:

<RadioButton 
    Content="{Resx PatternDialog.MatchOnlySuffix, DefaultValue='suffix'}"
    IsChecked="{Binding dnsLabelCount, Converter={local:DnsLabelCountToBoolConverter}}"/>

Radio Button 2:

<RadioButton 
    Name="matchUpToNumberSuffixRb"
    Content="{Resx PatternDialog.MatchUpToNumberSuffix, DefaultValue='Match'}"
    IsChecked="{Binding dnsLabelCount, Converter={local:DnsLabelCountToBoolConverter Invert=True}}"/>

The IntegerUpDown:

<IntegerUpDown 
    Name="updown"
    Value="{Binding dnsLabelCount}"
    Width="55" 
    ForceRange="True"
    MinValue="1"
    MaxValue="100"
    IsEnabled="{Binding IsChecked, ElementName=matchUpToNumberSuffixRb}"/>

This is my converter, which I know should not be so, but I'm not sure what to change it to.

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    var result = (int)value == 1;
    return Invert ? !result : result;
}

Solution

  • add a small Delay to Binding (Value="{Binding dnsLabelCount, Delay=250}"), and the source property will not be updated immediately