コード例 #1
0
        public void Attach_NoStateNamesSet_DoesNothing()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior dataStateBehavior = CreateEmptyDataStateBehavior();

            AttachBehavior(dataStateBehavior, stateGrid);
            // Attaching an empty DataStateBehavior should not cause any problems.
        }
コード例 #2
0
        public void TrueStateChangesToInvalidValue_ThrowsArgumentException()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior dataStateBehavior = CreateEmptyDataStateBehavior();

            AttachBehavior(dataStateBehavior, stateGrid);
            dataStateBehavior.TrueState = "TrueState";
            dataStateBehavior.TrueState = "NonExistantState";
        }
コード例 #3
0
        public void BindingChangesToNotMatchValue_TransitionsToFalseState()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior      dataStateBehavior = CreateDataStateBehaviorInTrueState();
            VisualStateManagerStub vsmStub           = VisualStateHelper.AttachCustomVSM(stateGrid);

            AttachBehavior(dataStateBehavior, stateGrid);

            dataStateBehavior.Binding = CreateObject();
            Assert.AreEqual(vsmStub.LastStateName, VisualStateHelper.DefaultFalseStateName, "Binding change to no longer match Value should have caused a transition to the FalseState");
        }
コード例 #4
0
        public void ValueChangesToMatchBinding_TransitionsToTrueState()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior      dataStateBehavior = CreateDataStateBehaviorInFalseState();
            VisualStateManagerStub vsmStub           = VisualStateHelper.AttachCustomVSM(stateGrid);

            AttachBehavior(dataStateBehavior, stateGrid);

            dataStateBehavior.Value = dataStateBehavior.Binding;
            Assert.AreEqual(vsmStub.LastStateName, VisualStateHelper.DefaultTrueStateName, "Value change to match Binding should have caused a transition to the TrueState");
        }
コード例 #5
0
        public void FalseStateChanges_TransitionsToNewFalseState()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior      dataStateBehavior = CreateDataStateBehaviorInFalseState();
            VisualStateManagerStub vsmStub           = VisualStateHelper.AttachCustomVSM(stateGrid);

            AttachBehavior(dataStateBehavior, stateGrid);

            dataStateBehavior.FalseState = VisualStateHelper.ArbitraryThirdStateName;
            Assert.AreEqual(vsmStub.LastStateName, VisualStateHelper.ArbitraryThirdStateName, "Change in FalseState should have caused a transition to the new state, as Binding does not match Value.");
        }
コード例 #6
0
        public void Attach_FalseStateDoesNotExist_ThrowsArgumentException()
        {
            Grid stateGrid = VisualStateHelper.CreateObjectWithStates <Grid>();
            DataStateBehavior dataStateBehavior = CreateEmptyDataStateBehavior();

            dataStateBehavior.FalseState = "NonExistantState";
            using (new StubWindow(stateGrid))
            {
                AttachBehavior(dataStateBehavior, stateGrid);
            }
        }
コード例 #7
0
        public void GetVisualStateGroups_UserControlControlWithChildStates_ReturnsChildStates()
        {
            Grid        stateGrid   = VisualStateHelper.CreateObjectWithStates <Grid>();
            UserControl userControl = CreateUserControlWithContent(stateGrid);

            using (new StubWindow(userControl))
            {
                IList vsgs = VisualStateUtilities.GetVisualStateGroups(userControl);
                Assert.AreEqual(vsgs.Count, 1, "Should find 1 VisualStateGroup on the UserControl");
            }
        }
コード例 #8
0
        public void GoToState_OnUserControl_WorksProperly()
        {
            Grid        stateGrid   = VisualStateHelper.CreateObjectWithStates <Grid>();
            UserControl userControl = CreateUserControlWithContent(stateGrid);

            userControl.Content = stateGrid;

            bool success = VisualStateUtilities.GoToState(userControl, VisualStateHelper.ArbitraryThirdStateName, true);

            Assert.IsTrue(success, "GoToState on a valid UserControl state should navigate to the state correctly.");
        }
コード例 #9
0
        public void Invoke_UseTransitionsIsFalse_TransitionsAreNotUsed()
        {
            Grid                   stateGrid       = VisualStateHelper.CreateObjectWithStates <Grid>();
            GoToStateAction        goToStateAction = CreateTestGoToStateAction();
            VisualStateManagerStub vsm             = VisualStateHelper.AttachCustomVSM(stateGrid);
            StubTrigger            trigger         = AttachAction(goToStateAction, stateGrid);

            goToStateAction.StateName      = VisualStateHelper.ArbitraryThirdStateName;
            goToStateAction.UseTransitions = false;
            trigger.FireStubTrigger();

            Assert.IsTrue(vsm.LastUseTransitions.HasValue && !vsm.LastUseTransitions.Value, "UseTransitions should be respected by the GoToState call.");
        }
コード例 #10
0
        public void FindNearestStatefulControl_ContextNestedSeveralLevelsDeep_FindsAppropriateParent()
        {
            Button      button      = CreateButton();
            Grid        grid        = VisualStateHelper.CreateObjectWithStates <Grid>();
            UserControl userControl = CreateUserControlWithContent(grid);

            grid.Children.Add(button);

            FrameworkElement nearestControl;

            VisualStateUtilities.TryFindNearestStatefulControl(button, out nearestControl);
            Assert.AreEqual(nearestControl, userControl, "Using child Grid of UserControl as context, closest stateful control should be UserControl.");
        }
コード例 #11
0
        public void Invoke_TargetObjectSet_CallsGoToStateOnTarget()
        {
            UserControl            statefulUC      = VisualStateHelper.CreateObjectWithStates <UserControl>();
            Grid                   statefulGrid    = VisualStateHelper.CreateObjectWithStates <Grid>();
            VisualStateManagerStub gridVSM         = VisualStateHelper.AttachCustomVSM(statefulGrid);
            Grid                   childGrid       = CreateEmptyGrid();
            GoToStateAction        goToStateAction = CreateTestGoToStateAction();
            StubTrigger            trigger         = AttachAction(goToStateAction, childGrid);

            // set up the tree structure
            statefulUC.Content = childGrid;

            // target the action and set the StateName
            goToStateAction.TargetObject = statefulGrid;
            goToStateAction.StateName    = VisualStateHelper.ArbitraryThirdStateName;

            trigger.FireStubTrigger();
            Assert.AreEqual(gridVSM.LastStateName, VisualStateHelper.ArbitraryThirdStateName, "test");
        }