public void VectorChanged_ActionChangedToNonAction_ExceptionThrown() { ActionCollection actionCollection = new ActionCollection(); actionCollection.Add(new StubAction()); TestUtilities.AssertThrowsException(() => actionCollection[0] = new Button()); }
protected ActionCollection GetActionCollection(DependencyProperty collectionProperty) { ActionCollection actionCollection = (ActionCollection)this.GetValue(collectionProperty); if (actionCollection == null) { actionCollection = new ActionCollection(); this.SetValue(collectionProperty, actionCollection); } return actionCollection; }
/// <summary> /// Executes all actions in the <see cref="ActionCollection"/> and returns their results. /// </summary> /// <param name="sender">The <see cref="System.Object"/> which will be passed on to the action.</param> /// <param name="actions">The set of actions to execute.</param> /// <param name="parameter">The value of this parameter is determined by the calling behavior.</param> /// <returns>Returns the results of the actions.</returns> public static IEnumerable <object> ExecuteActions(object sender, ActionCollection actions, object parameter) { List <object> results = new List <object>(); if (actions == null || Windows.ApplicationModel.DesignMode.DesignModeEnabled) { return(results); } foreach (DependencyObject dependencyObject in actions) { IAction action = (IAction)dependencyObject; results.Add(action.Execute(sender, parameter)); } return(results); }
/// <summary> /// Executes all actions in the <see cref="ActionCollection"/> and returns their results. /// </summary> /// <param name="sender">The <see cref="System.Object"/> which will be passed on to the action.</param> /// <param name="actions">The set of actions to execute.</param> /// <param name="parameter">The value of this parameter is determined by the calling behavior.</param> /// <returns>Returns the results of the actions.</returns> public static IEnumerable<object> ExecuteActions(object sender, ActionCollection actions, object parameter) { List<object> results = new List<object>(); if (actions == null || Windows.ApplicationModel.DesignMode.DesignModeEnabled) { return results; } foreach (DependencyObject dependencyObject in actions) { IAction action = (IAction)dependencyObject; results.Add(action.Execute(sender, parameter)); } return results; }
private void ActionCollection_VectorChanged(IObservableVector <DependencyObject> sender, IVectorChangedEventArgs eventArgs) { CollectionChange collectionChange = eventArgs.CollectionChange; if (collectionChange == CollectionChange.Reset) { foreach (DependencyObject item in this) { ActionCollection.VerifyType(item); } } else if (collectionChange == CollectionChange.ItemInserted || collectionChange == CollectionChange.ItemChanged) { DependencyObject changedItem = this[(int)eventArgs.Index]; ActionCollection.VerifyType(changedItem); } }
public void ExecuteActions_ActionsWithResults_ResultsInActionOrder() { string[] expectedReturnValues = { "A", "B", "C" }; ActionCollection actions = new ActionCollection(); foreach (string returnValue in expectedReturnValues) { actions.Add(new StubAction(returnValue)); } List<object> results = Interaction.ExecuteActions(null, actions, null).ToList(); Assert.AreEqual(expectedReturnValues.Length, results.Count, "Should have the same number of results as IActions."); for (int resultIndex = 0; resultIndex < results.Count; resultIndex++) { Assert.AreEqual(expectedReturnValues[resultIndex], results[resultIndex], "Results should be returned in the order of the actions in the ActionCollection."); } }
public void ExecuteActions_MultipleActions_AllActionsExecuted() { ActionCollection actions = new ActionCollection(); actions.Add(new StubAction()); actions.Add(new StubAction()); actions.Add(new StubAction()); Button sender = new Button(); string parameterString = "TestString"; Interaction.ExecuteActions(sender, actions, parameterString); foreach (StubAction action in actions) { Assert.AreEqual(1, action.ExecuteCount, "Each IAction should be executed once."); Assert.AreEqual(sender, action.Sender, "Sender is passed to the actions."); Assert.AreEqual(parameterString, action.Parameter, "Parameter is passed to the actions."); } }