diff --git a/Src/xWorks/RecordEditView.cs b/Src/xWorks/RecordEditView.cs index 04eacb3deb..b3c740b461 100644 --- a/Src/xWorks/RecordEditView.cs +++ b/Src/xWorks/RecordEditView.cs @@ -411,6 +411,8 @@ bool ShowRecordOnIdle(object parameter) } else { + // Switching from New with no record leaves the tree uninitialized. + EnsureDataTreeInitialized(); EnsureDataTreeVisible(); m_dataEntryForm.Hide(); m_dataEntryForm.Reset(); // in case user deleted the object it was based upon. diff --git a/Src/xWorks/xWorksTests/Avalonia/Hosting/RecordEditViewSwitchTests.cs b/Src/xWorks/xWorksTests/Avalonia/Hosting/RecordEditViewSwitchTests.cs index 7d6aaca7a2..33e66a0587 100644 --- a/Src/xWorks/xWorksTests/Avalonia/Hosting/RecordEditViewSwitchTests.cs +++ b/Src/xWorks/xWorksTests/Avalonia/Hosting/RecordEditViewSwitchTests.cs @@ -194,6 +194,29 @@ public void RegisteredRecordEditTools_ResolveToAvalonia_WhenUIModeIsNew(string t toolValue); } + // Switching from New to the WinForms view with no current record must still initialize + // the DataTree: leaving the tool (or closing the window) calls its PrepareToGoAway. + [Test] + public void FlipNewToLegacy_WithNoCurrentRecord_PrepareToGoAwaySucceeds() + { + m_propertyTable.SetProperty("UIMode", "New", true); + m_propertyTable.SetPropertyPersistence("UIMode", false); + + LoadRecordEditView("ProdRestrictEdit"); + DrainMediatorAndIdleQueues(); + + var control = m_propertyTable.GetValue("currentContentControlObject", null) as RecordEditView; + Assert.That(control, Is.Not.Null); + Assert.That(control.Clerk.CurrentObject, Is.Null, "precondition: the list is empty"); + Assert.That(GetPrivateFieldValue(control, "m_activeUIFramework"), Is.EqualTo(UIFramework.Avalonia)); + + m_propertyTable.SetProperty("UIMode", "Legacy", true); + DrainMediatorAndIdleQueues(); + Assert.That(GetPrivateFieldValue(control, "m_activeUIFramework"), Is.EqualTo(UIFramework.Legacy)); + + Assert.That(control.PrepareToGoAway(), Is.True); + } + // LT-22811: View > Refresh and closing the Styles dialog reach the Avalonia view through // RefreshDisplay, which recomposes it at Normal's new size. [Test]