Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
490
wpf Radio Button DataBindings
posted

 

Hi,

I have two radiobuttons on my view and there IsChecked property is binded to the ViewModel property IsDynamic , problem

is that when i change the selection of first radion button first time the binding works ,but when i check another

radion button the IsChecked property is not updated. I am using the enum boolean converter. My xaml file

is

<

 

 

RadioButton Grid.Column="0" Content="Static" IsChecked="{Binding Path=IsDynamic, Converter={StaticResource enumBooleanConverter },ConverterParameter=Static,Mode=TwoWay}" TabIndex="1" GroupName="Static"/>

 

 

 

 

 

 

<RadioButton Content="Dynamic" Grid.Row="1" Margin="0,30,96,16" IsChecked="{Binding Path=IsDynamic, Converter={StaticResource enumBooleanConverter},ConverterParameter=Dynamic,Mode=TwoWay}" IsEnabled="{Binding IsDynamicViewEnabled}" TabIndex="2" Width="61" IsHitTestVisible="False" Checked="RadioButton_Checked" GroupName

="Dynamic"/>

and the EnumBooleanConverter is

 

 

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 (Enum.IsDefined(value.GetType(), value) == false)

 

 

return DependencyProperty.UnsetValue;

 

 

object parameterValue = 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 Enum.Parse(targetType, parameterString);

 

}

The isDynamic property on ViewModel is as follows

 

 

 

 

 

 

 

 

 

 

public

 

 

 

AccountSetDynamic

IsDynamic

{

 

 

 

set

{

 

 

 

//this.currentAccountSet.IsDynamic = value;

 

 

 

if (value.Equals(AccountSetDynamic

.Dynamic))

{

 

 

 

 

this.CurrentAccountSet.IsDynamic = true

;

}

 

 

 

else if(value.Equals(AccountSetDynamic

.Static))

{

 

 

 

 

this.CurrentAccountSet.IsDynamic = false

;

}

 

 

 

this.isDynamic = value

;

 

 

 

this.RaisePropertyChanged(() => this

.IsDynamic);

}

 

 

 

get

{

 

 

 

return this

.isDynamic;

}

and the ENUM is as follows

 

 

public enum AccountSetDynamic

{

Static=0,

Dynamic=1

}

i cannot figure out where i am doing wrong ,please help out