I'm using wpf + mvvm and am trying to implement a conditional converter. Here is what I'm doing in the xaml:
<CheckBox.IsChecked>
<MultiBinding Converter="{StaticResource pageSourceConverter}">
<Binding Path="CurrentPage.Source"/>
<Binding Path="Project.Type1.MachineTypes.Rotating"/>
<Binding Path="Project.Type2.MachineTypes.Rotating" />
<Binding Path="Project.Type3.MachineTypes.Rotating" />
<Binding Path="Project.Type4.MachineTypes.Rotating" />
</MultiBinding>
</CheckBox.IsChecked>
And the MultiConverter:
public class PageSourceConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
String pageSource = values[0] as String;
if (pageSource == "Type1")
return values[1];
else if (pageSource == "Type2")
return values[2];
else if (pageSource == "Type3")
return values[3];
else if (pageSource == "Type4")
return values[4];
else
return null;
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
return null;
}
}
So what I want to do is conditionally bind an element on a page to different Models I have in the viewController based on the page type the user is on.
What do I need to do for the convertback? I don't know how to tell which element in the return array the value belongs to. Any ideas?