Return an unset value in value converter
Using a value converter in WPF, you can return something like
DependecyProperty.UnsetValue or Binding.DoNothing as special values to say
leave the binding alone. Is there a similar mechanism in MVVMCross?
To be more specific about what I'm trying to do, is I have a view model
property that is a three-state enum that I need to bind to 3 binary
controls. So I thought I could bind each of the controls to a MyEnum ->
bool converter that will have a conversion parameter set to the value of
the converter and in the Convert method it will return true if the MyEnum
state is equal to the parameter and false otherwise. So far so good. But I
want this binding to be two-way, so I need to convert back. My convert
back works something like this:
protected override MyEnum ConvertBack(bool value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
if (parameter is MyEnum)
{
if (value)
{
return (MyEnum)parameter; // this is fine
}
else
{
return ???
}
}
return base.ConvertBack(value, targetType, parameter, culture);
}
Basically, what I want to be able to do is say, if the state of my control
is true update the bound property on my view model to be the same as the
parameter, if not, leave the view model property alone.
Maybe this is the problem with using the strongly typed value converters?
No comments:
Post a Comment