So I have been trying to get guard clauses to work with Caliburn.Micro and a bound textbox.
The View:
<TextBox x:Name="UserAccount_DisplayName" Margin="-10,-5,-10,8"/>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBar.Buttons>
<cal:AppBarButton IconUri="\Resources\Iconography\appbar.check.rest.png"
Text="Save"
Message="SaveAndNavigateToAddAccountView" />
</shell:ApplicationBar.Buttons>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
The ViewModel:
public class EditAccountNameViewModel: PropertyChangedBase
public Account UserAccount
{
get
{
return account;
}
set
{
account = value;
NotifyOfPropertyChange(() => UserAccount);
NotifyOfPropertyChange(() => CanSaveAndNavigateToAddAccountView);
}
}
public bool CanSaveAndNavigateToAddAccountView
{
get
{
if (string.IsNullOrEmpty(UserAccount.DisplayName) == true)
{
return false;
}
return true;
}
}
public void SaveAndNavigateToAddAccountView()
{
CommitAccountToStorage();
navigationService.UriFor<AddAccountViewModel>().Navigate();
}
For some reason the guard clause is not firing after I begin typing in the textbox, which is what I would have assumed should happen. Any ideas?