Итак, я полагаю, вы хотите одну кнопку для входа и выхода?
<Button Content="{Binding ButtonContent}" Command="{Binding ClickCommand}"/>
А затем в вашей модели представления:
private string _ButtonContent;
public string ButtonContent
{
get { return _ButtonContent;?? (_ButtonContent = "Login"); }
set
{
_ButtonContent = value;
NotifyPropertyChanged("ButtonContent");
}
}
private ICommand _ClickCommand;
public ICommand ClickCommand
{
get { return _ClickCommand ?? (_ClickCommand = _LoginCommand); }
set
{
_ClickCommand = value;
NotifyPropertyChanged("ClickCommand");
}
}
private ICommand _LoginCommand = new RelayCommand(f => Login());
private ICommand _LogoutCommand = new RelayCommand(f => Logout());
private void Login()
{
// Do your Login stuff here
// Create if statement for when to Login is not completed succesfully
// switch the button
ButtonText = "Logout";
ClickCommand = LoginCommand;
}
private void Logout()
{
// Do your Logout stuff here
// switch the button
ButtonText = "Login";
ClickCommand = LogoutCommand;
}
Чтобы это работало, вам нужно реализовать NotifyPropertyChanged () , чтобы модель представления знала, что какое-то свойство изменилось.