If a Screen is deactivated from closed, make sure it's activated again

Relates to #14
This commit is contained in:
Antony Male 2016-11-17 12:49:39 +00:00
parent 5a5cfc5cfb
commit 97567f9cc2
2 changed files with 25 additions and 0 deletions

View File

@ -182,6 +182,10 @@ namespace Stylet
[SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Justification = "As this is a framework type, don't want to make it too easy for users to call this method")]
void IScreenState.Deactivate()
{
// Avoid going from Closed -> Deactivated without going via Activated
if (this.ScreenState == ScreenState.Closed)
((IScreenState)this).Activate();
this.SetState(ScreenState.Deactivated, (oldState, newState) =>
{
this.OnDeactivate();

View File

@ -22,6 +22,14 @@ namespace StyletUnitTests
public MyScreen() { }
public MyScreen(IModelValidator validator) : base(validator) { }
public void Reset()
{
this.OnActivateCalled = false;
this.OnInitialActivateCalled = false;
this.OnDeactivateCalled = false;
this.OnCloseCalled = false;
}
public new void SetState(ScreenState newState, Action<ScreenState, ScreenState> changedHandler)
{
base.SetState(newState, changedHandler);
@ -435,5 +443,18 @@ namespace StyletUnitTests
((IScreenState)this.screen).Activate();
Assert.True(this.screen.OnInitialActivateCalled);
}
[Test]
public void DeactivateAfterCloseCausesActivate()
{
((IScreenState)this.screen).Activate();
((IScreenState)this.screen).Close();
this.screen.Reset();
((IScreenState)this.screen).Deactivate();
Assert.True(this.screen.OnInitialActivateCalled);
Assert.True(this.screen.OnActivateCalled);
Assert.True(this.screen.OnDeactivateCalled);
}
}
}