You may need to use a MultiBinding
:
<TabItem Name="MyTab" Header="This should be enabled when result is 2">
<TabItem.IsEnabled>
<MultiBinding Converter={StaticResource MyAddConverter}>
<Binding Path=ValueA UpdateSourceTrigger=PropertyChanged />
<Binding Path=ValueB UpdateSourceTrigger=PropertyChanged />
</MultiBinding>
</TabItem.IsEnabled>
<!--Some other stuff-->
</TabItem>
In your ViewModel, you should have the following (assuming your ViewModel implements INotifyPropertyChanged
):
public double ValueA
{
get { return _valueA; }
set
{
_valueA = value;
OnPropertyChanged("ValueA");
}
}
And same for ValueB
, which would allow WPF to update the Binding
every time either ValueA
or ValueB
changes
Your converter should look like this:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double valueA = (double)values[0];
double valueB = (double)values[1];
return valueA + valueB == 2;
}
This would allow you to have one external method defined in the Converter, which will be called again every time ValueA or ValueB would change.
I'd say that's all you need =)