Say i have a tab control that displays data of various types, eg EditorTabViewModel
, PreviewTabViewModel
both inheriting from TabViewModel
. The implementation is similar to the tutorial on MSDN
I want to enable buttons depending on the active tab, whether its an EditorTabViewModel
or a PreviewTabViewModel
. How can I achieve this?
UPDATE
public ICommand EditorCommand
{
get
{
if (_editorCommand == null) {
_editorCommand = new RelayCommand(() =>
{
MessageBox.Show("Editor");
}, () =>
{
var enabled = true;
var viewSource = CollectionViewSource.GetDefaultView(Tabs);
viewSource.CurrentChanged += (o, e) =>
{
if (viewSource.CurrentItem is EditorTabViewModel)
{
enabled = false;
}
};
return enabled;
});
}
return _editorCommand;
}
}
UPDATE 2
public ICommand PreviewCommand
{
get
{
if (_previewCommand == null) {
_previewCommand = new RelayCommand(() =>
{
MessageBox.Show("Preview");
}, () =>
{
var viewSource = CollectionViewSource.GetDefaultView(Tabs);
var enabled = viewSource.CurrentItem is EditorTabViewModel;
viewSource.CurrentChanged += (o, e) =>
{
CommandManager.InvalidateRequerySuggested();
};
return enabled;
});
}
return _previewCommand;
}
}