/// <summary> /// Raises current changing events /// </summary> /// <param name="e">The event args</param> protected virtual void OnCurrentChanging(CurrentChangingEventArgs e) { CurrentChangingEventHandler handler = this.CurrentChanging; if (handler != null) { handler(this, e); } }
private void OnCurrentChanging(CurrentChangingEventArgs e) { CurrentChangingEventHandler handler = CurrentChanging; if (handler != null) { handler(this, e); } }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// currentchangingeventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this CurrentChangingEventHandler currentchangingeventhandler, Object sender, CurrentChangingEventArgs e, AsyncCallback callback) { if (currentchangingeventhandler == null) { throw new ArgumentNullException("currentchangingeventhandler"); } return(currentchangingeventhandler.BeginInvoke(sender, e, callback, null)); }
/// <summary> /// Raise the CurrentChanging event. /// </summary> /// <returns> /// A value indicating whether the change should be cancelled. /// </returns> private bool RaiseCurrentChanging() { bool cancel = false; CurrentChangingEventHandler handler = this.CurrentChanging; if (handler != null) { CurrentChangingEventArgs args = new CurrentChangingEventArgs(true); handler(this, args); cancel = args.Cancel; } return(cancel); }
public void CancelingCurrencyChangeIsRespectedOnCommitEdit() { City first = new City { Name = "1" }; City second = new City { Name = "2" }; MockEntityContainer ec = new MockEntityContainer(); ec.CreateSet <City>(EntitySetOperations.All); IPagedEntityList pagedList = new MockPagedEntityList(ec.GetEntitySet <City>(), null); PagedEntityCollectionView view = new PagedEntityCollectionView(pagedList, () => { }); view.Add(first); view.Add(second); bool canChangeCurrency = true; CurrentChangingEventHandler changingHandler = (sender, e) => { if (!canChangeCurrency) { Assert.IsTrue(e.IsCancelable, "Event should be cancelable when commiting an edit."); e.Cancel = true; } }; EventHandler changedHandler = (sender, e) => { if (!canChangeCurrency) { Assert.Fail("Currency changes should only occur when canChangeCurrency is true."); } }; view.CurrentChanging += changingHandler; view.CurrentChanged += changedHandler; view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); Assert.IsTrue(view.MoveCurrentTo(second), "We should be able to move current to the second item."); // Commit an edit but do not allow the currency to change canChangeCurrency = false; view.EditItem(second); second.Name = "0"; view.CommitEdit(); Assert.AreEqual(view[1], second, "The edited item should not have moved."); // Commit an edit and this time allow the currency to change canChangeCurrency = true; view.EditItem(second); second.Name = "00"; view.CommitEdit(); Assert.AreEqual(view[0], second, "The edited item should have moved to the first position in the view."); }