I'm using model-view-viewmodel I currently have a class with 3 pieces of data: 2 integers and an enumeration.
Its constructor looks like this:
//C#
public Outcome(OutcomeEnum outcomeEnum, Int32 acutalOutcomeData, Int32 expectedOutcomeData)
{
m_outcomeEnum = outcomeEnum;
m_actualData = acutalOutcomeData;
m_expectedData = expectedOutcomeData;
}
I have 2 ComboBoxes next to each other that I have bound to one List of outcome objects (List<Outcome>
) which I use to the "actual" and "expected" integer values.
This section of code looks like this: (The SelectedItem and ItemsSource are dependency properties in the viewmodel )
<ComboBox
x:Name="PART_cbExpectedOutcome"
Grid.Column="1"
ItemsSource="{Binding Path=OutcomeList}"
SelectedItem="{Binding SelectedExpectedOutcome, Mode=TwoWay}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Path=ExpectedOutcomeData, Converter={StaticResource OutcomeDataToStringConverter}, ConverterParameter=Expected }" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox
x:Name="PART_cbActualOutcome"
Grid.Column="2"
ItemsSource="{Binding Path=OutcomeList}"
SelectedItem="{Binding SelectedActualOutcome, Mode=TwoWay}"
>
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Label Content="{Binding Path=ActualOutcomeData, Converter={StaticResource OutcomeDataToStringConverter}, ConverterParameter=Actual}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
My problem is: I'd like to pass a reference to the Outcome object into the IValueConverter that I'm using to convert between, but this appears to not be possible using the IConvertParameter but rather I would be forced to use Multibinding per the msdn post here.
I'd like to simplify my approach as creating a multibinding for something relatively as simple as this seems like overkill.
I'd like to do only one thing with the Outcome object that I seek to pass into IValueConverter, which is to determine the enumeration type of OutcomeEnum so I can provide the proper formatting of the expected or actual data value.
Is there any simpler way for me to be able to pass the Outcome object into the IValueConverter OutcomeDataToStringConverter
while maintaining a two-way binding with this list of Outcome objects? I'm open to suggestions.