WPF OneWayToSource Binding Initial Value

I have a RadioButton element, the IsChecked property IsChecked bound to MyProperty in the ViewModel . For some reason, Binding has OneWayToSource mode, it OneWayToSource value from RadioButton.IsChecked to ViewModel.MyProperty .

RadioButton.IsChecked was initially false , now. I want to set the initial value from the ViewModel , which may even be true . I cannot do this because the property is busy with binding.

Is it possible to use Binding with this mode and set the default value for the bound property in the UI? Something like that:

 <RadioButton IsChecked="{Binding MyProperty, Mode=OneWayToSource, DefaultVaule=???}"> </RadioButton> 
+7
default-value wpf binding oneway
source share
1 answer

If I understood you correctly, I think this may help:

You can determine the default value using the TargetNullValue property. You can determine the value of FallbackValue in case of an error, for example:

 <TextBox Text="{Binding MyProperty, TargetNullValue=0, FallbackValue=10}" /> 

see here: enter link here

+8
source share

All Articles