Try to define a command for the buttons which are responsible for the change of the view.
You should use a Delegate Command for this.
class DelegateCommand : ICommand
{
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public event EventHandler CanExecuteChanged;
public DelegateCommand(Action<object> execute)
{
_execute = execute;
}
public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
if (_canExecute == null)
{
return true;
}
return _canExecute(parameter);
}
public void Execute(object parameter)
{
_execute(parameter);
}
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, EventArgs.Empty);
}
}
}
It gives you the opportunity to define whether the command is executable or not.
To do this, try doing something like this:
public ICommand SwitchViewCommand { get; set; }
public void SwitchView(object parameter)
{
}
public bool AllowSwitchView(object parameter)
{
}
And dont forget to instantiate your command:
SwitchViewCommand = new DelegateCommand(SwitchView, AllowSwitchView);
I hope this will help you :)
And sorry for my bad english.