public void UnregisterServiceOnDetaching() { Button control = new Button(); TestVM vm1 = TestVM.Create(); TestServiceBase service = new TestServiceBase(); Interaction.GetBehaviors(control).Add(service); control.DataContext = vm1; Assert.AreEqual(service, vm1.GetService <ITestService>()); Interaction.GetBehaviors(control).Remove(service); Assert.AreEqual(null, vm1.GetService <ITestService>()); }
public void UnregisterServiceOnUnloaded() { Button control = new Button(); TestVM vm1 = TestVM.Create(); TestServiceBase service = new TestServiceBase() { UnregisterOnUnloaded = true }; Interaction.GetBehaviors(control).Add(service); control.DataContext = vm1; Assert.AreEqual(service, vm1.GetService <ITestService>()); Window.Content = control; Window.Show(); Assert.AreEqual(service, vm1.GetService <ITestService>()); Window.Content = null; DispatcherHelper.DoEvents(); Assert.AreEqual(null, vm1.GetService <ITestService>()); }
public void T250427() { Grid mainV = new Grid(); TestVM mainVM = TestVM.Create(); TestServiceBase mainService = new TestServiceBase(); Interaction.GetBehaviors(mainV).Add(mainService); mainV.DataContext = mainVM; Grid childV = new Grid(); TestVM childVM = TestVM.Create(); TestServiceBase childService = new TestServiceBase(); Interaction.GetBehaviors(childV).Add(childService); mainV.Children.Add(childV); Assert.AreEqual(childService, mainVM.GetService <ITestService>()); childV.DataContext = childVM; Assert.AreEqual(mainService, mainVM.GetService <ITestService>()); Assert.AreEqual(childService, childVM.GetService <ITestService>()); }