public virtual void ShouldChangeVisualStateWhenContainerIsSet() { TimePicker tip = new TimePicker(); TimePickerPopup tpp = DefaultTimePickerPopupToTest; TestVisualStateManager vsmTpp = new TestVisualStateManager(); bool tipIsLoaded = false; tip.Loaded += delegate { tipIsLoaded = true; }; bool tppIsLoaded = false; tpp.Loaded += delegate { tppIsLoaded = true; }; // Add the element to the test surface and wait until it's loaded EnqueueCallback(() => TestPanel.Children.Add(tip)); EnqueueCallback(() => TestPanel.Children.Add(tpp)); EnqueueConditional(() => tipIsLoaded); EnqueueConditional(() => tppIsLoaded); EnqueueCallback(() => { FrameworkElement root2 = tpp.GetVisualDescendents().First() as FrameworkElement; VisualStateManager.SetCustomVisualStateManager(root2, vsmTpp); }); EnqueueCallback(() => { TestPanel.Children.Remove(tpp); tip.Popup = tpp; }); EnqueueCallback(() => Assert.IsTrue(vsmTpp.ChangedStates.Contains("Contained"))); EnqueueTestComplete(); }