You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The DefaultContent set in ViewModelControlHost (warning! the file is named ViewModelViewHost.cs) is Disposed when clearing the controls in the container. So, next time it should be used is not ok.
Step to reproduce
Configure a simple ReactiveUI project using Winforms:
Form1 (two buttons + ViewModelControlHost)
TestVM
TestV (UserControl)
Register the TestV for IViewFor<TestVM> (Locator.CurrentMutable.Register(() => new TestV(), typeof(TestVM));)
Form1 ctor: setup the defaultcontent of the ViewModelControlHost to be a simple label with text in it (i.e.: "Nothing here")
Form1.button1.Click -> set ViewModelControlHost.ViewModel = new TestVM();
Form1.button2.Click -> set ViewModelControlHost.ViewModel = null
Run app:
label with text "Nothing here" (of DefaultContent) is shown
The label with text "Nothing here" should be seen again when setting null to ViewModelControlHost.ViewModel
Screenshots 🖼️
No response
IDE
No response
Operating system
No response
Version
No response
Device
No response
ReactiveUI Version
Latest as of now (18.0.10), but I think this problem has been there for a long, long time.
Additional information ℹ️
I think the problem is only related to disposing all controls inside container when Content is changed.
This also disposes the DefaultContent control, which it really should not.
With this change in code (file ViewModelViewHost.cs, line 161) from:
// clear out existing visible control view
foreach (Control? c in Controls)
{
c?.Dispose();
Controls.Remove(c);
}
to:
// clear out existing visible control view
foreach (Control? c in Controls)
{
if (c != DefaultContent)
{
c?.Dispose();
}
Controls.Remove(c);
}
The problem is gone.
RoutedViewHost follows a different strategy, and so it seems to only dispose the last view used, but not the DefaultContent one. So I expect it to be working fine.
The text was updated successfully, but these errors were encountered:
ismdiego
changed the title
[Bug]: DefaultContent in ViewModelViewHost (Winforms) is Disposed
[Bug]: DefaultContent in ViewModelControlHost (Winforms) is Disposed
May 19, 2022
Describe the bug 🐞
The DefaultContent set in ViewModelControlHost (warning! the file is named ViewModelViewHost.cs) is Disposed when clearing the controls in the container. So, next time it should be used is not ok.
Step to reproduce
Configure a simple ReactiveUI project using Winforms:
IViewFor<TestVM>
(Locator.CurrentMutable.Register(() => new TestV(), typeof(TestVM));
)Run app:
Reproduction repository
https://github.com/ismdiego/reactiveui_bug01
Expected behavior
The label with text "Nothing here" should be seen again when setting null to ViewModelControlHost.ViewModel
Screenshots 🖼️
No response
IDE
No response
Operating system
No response
Version
No response
Device
No response
ReactiveUI Version
Latest as of now (18.0.10), but I think this problem has been there for a long, long time.
Additional information ℹ️
I think the problem is only related to disposing all controls inside container when Content is changed.
This also disposes the DefaultContent control, which it really should not.
With this change in code (file ViewModelViewHost.cs, line 161) from:
to:
The problem is gone.
RoutedViewHost follows a different strategy, and so it seems to only dispose the last view used, but not the DefaultContent one. So I expect it to be working fine.
The text was updated successfully, but these errors were encountered: