EDIT: I tested my other code and it did not work. It was just an idea. Here's a method that works (although I agree with Alex that the code in MVVM is good at setting up the View).
In this case, I created a converter that takes two logical values: if a tab is selected, and if we can change the tabs. If both of them are set to false, we return false to disable the tab. If set to true, we leave the tab enabled.
Here is the code. I have a property in my VM called CanChangeTabs and an instance of MyConverter in Window.Resources is called Converter.
XAML inTabItem:
<TabItem.IsEnabled> <MultiBinding Converter="{StaticResource Converter}"> <Binding RelativeSource="{RelativeSource Self}" Path="IsSelected" /> <Binding Path="CanChangeTabs" /> </MultiBinding> </TabItem.IsEnabled>
Converter
public class MyConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { foreach (object value in values) { if ((bool)value) { return true; } } return false; } public object[] ConvertBack(object values, Type[] targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
source share