Skip to content

Commit 46a20be

Browse files
committed
Clean up leak in ViewModelViewHost
1 parent 075ff71 commit 46a20be

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

ReactiveUI.Platforms/Xaml/ViewModelViewHost.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace ReactiveUI.Xaml
2020
/// the ViewModel property and display it. This control is very useful
2121
/// inside a DataTemplate to display the View associated with a ViewModel.
2222
/// </summary>
23-
public class ViewModelViewHost : TransitioningContentControl
23+
public class ViewModelViewHost : TransitioningContentControl, IViewFor
2424
{
2525
/// <summary>
2626
/// The ViewModel to display
@@ -77,21 +77,23 @@ public ViewModelViewHost()
7777
.StartWith(platform.GetOrientation())
7878
.Select(x => x != null ? x.ToString() : default(string));
7979

80-
vmAndContract.Subscribe(x => {
81-
if (x.ViewModel == null) {
82-
Content = DefaultContent;
83-
return;
84-
}
80+
this.WhenActivated(d => {
81+
d(vmAndContract.Subscribe(x => {
82+
if (x.ViewModel == null) {
83+
Content = DefaultContent;
84+
return;
85+
}
8586

86-
var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
87-
var view = viewLocator.ResolveView(x.ViewModel, x.Contract) ?? viewLocator.ResolveView(x.ViewModel, null);
87+
var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
88+
var view = viewLocator.ResolveView(x.ViewModel, x.Contract) ?? viewLocator.ResolveView(x.ViewModel, null);
8889

89-
if (view == null) {
90-
throw new Exception(String.Format("Couldn't find view for '{0}'.", x.ViewModel));
91-
}
90+
if (view == null) {
91+
throw new Exception(String.Format("Couldn't find view for '{0}'.", x.ViewModel));
92+
}
9293

93-
view.ViewModel = x.ViewModel;
94-
Content = view;
94+
view.ViewModel = x.ViewModel;
95+
Content = view;
96+
}));
9597
});
9698
}
9799

0 commit comments

Comments
 (0)