コード例 #1
0
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            if (itemsControl.SelectedItem == null)
            {
                MessageBox.Show("No item is selected");
                return;
            }

            IEditableCollectionView editableCollectionView =
                itemsControl.Items as IEditableCollectionView;

            // Create a window that prompts the user to edit an item.
            ChangeItemWindow win = new ChangeItemWindow();

            editableCollectionView.EditItem(itemsControl.SelectedItem);
            win.DataContext = itemsControl.SelectedItem;

            // If the user submits the new item, commit the changes.
            // If the user cancels the edits, discard the changes.
            if ((bool)win.ShowDialog())
            {
                editableCollectionView.CommitEdit();
            }
            else
            {
                editableCollectionView.CancelEdit();
            }
        }
コード例 #2
0
        /// <summary>
        /// Puts the entity into editing mode if possible
        /// </summary>
        /// <param name="dataItem">The entity to edit</param>
        /// <returns>True if editing was started</returns>
        public bool BeginEdit(object dataItem)
        {
            if (dataItem == null)
            {
                return(false);
            }

#if FEATURE_IEDITABLECOLLECTIONVIEW
            IEditableCollectionView editableCollectionView = this.EditableCollectionView;
            if (editableCollectionView != null)
            {
                if ((editableCollectionView.IsEditingItem && (dataItem == editableCollectionView.CurrentEditItem)) ||
                    (editableCollectionView.IsAddingNew && (dataItem == editableCollectionView.CurrentAddItem)))
                {
                    return(true);
                }
                else
                {
                    editableCollectionView.EditItem(dataItem);
                    return(editableCollectionView.IsEditingItem);
                }
            }
#endif

            IEditableObject editableDataItem = dataItem as IEditableObject;
            if (editableDataItem != null)
            {
                editableDataItem.BeginEdit();
                return(true);
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Puts the entity into editing mode if possible
        /// </summary>
        /// <param name="dataItem">The entity to edit</param>
        /// <returns>True if editing was started</returns>
        public bool BeginEdit(object dataItem)
        {
            if (dataItem == null)
            {
                return(false);
            }

            IEditableCollectionView editableCollectionView = this.EditableCollectionView;

            if (editableCollectionView != null)
            {
                if (editableCollectionView.IsEditingItem && (dataItem == editableCollectionView.CurrentEditItem))
                {
                    return(true);
                }
                else
                {
                    editableCollectionView.EditItem(dataItem);
                    return(editableCollectionView.IsEditingItem);
                }
            }

            IEditableObject editableDataItem = dataItem as IEditableObject;

            if (editableDataItem != null)
            {
                editableDataItem.BeginEdit();
                return(true);
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Changes the name of a city on an item.
        /// </summary>
        /// <param name="sender">The Object that originated the event.</param>
        /// <param name="e">The event arguments.</param>
        void OnChangeCityClick(Object sender, RoutedEventArgs e)
        {
            IEditableCollectionView iEditableCollectionView = this.ListView.Items as IEditableCollectionView;

            iEditableCollectionView.EditItem(this.consumerCollection[3]);
            this.consumerCollection[3].City = "Aberdene";
            iEditableCollectionView.CommitEdit();
        }
コード例 #5
0
        /// <summary>
        /// Begins an edit transaction of the specified item.
        /// </summary>
        /// <param name="item">The item to edit.</param>
        void IEditableCollectionView.EditItem(Object item)
        {
            IEditableCollectionView iEditableCollectionView = this.currentView as IEditableCollectionView;

            if (iEditableCollectionView == null)
            {
                throw new InvalidOperationException(ExceptionMessage.Format(ExceptionMessages.MemberNotAllowedForView, "EditItem"));
            }
            iEditableCollectionView.EditItem(item);
        }
コード例 #6
0
        /// <summary>
        /// Begins an editing transaction on the given item.  The transaction is
        /// completed by calling either <seealso cref="IEditableCollectionView.CommitEdit"/> or
        /// <seealso cref="IEditableCollectionView.CancelEdit"/>.  Any changes made to the item during
        /// the transaction are considered "pending", provided that the view supports
        /// the notion of "pending changes" for the given item.
        /// </summary>
        void IEditableCollectionView.EditItem(object item)
        {
            IEditableCollectionView ecv = ProxiedView as IEditableCollectionView;

            if (ecv != null)
            {
                ecv.EditItem(item);
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.MemberNotAllowedForView, "EditItem"));
            }
        }
コード例 #7
0
        // Token: 0x06007410 RID: 29712 RVA: 0x00212F90 File Offset: 0x00211190
        void IEditableCollectionView.EditItem(object item)
        {
            IEditableCollectionView editableCollectionView = this.ProxiedView as IEditableCollectionView;

            if (editableCollectionView != null)
            {
                editableCollectionView.EditItem(item);
                return;
            }
            throw new InvalidOperationException(SR.Get("MemberNotAllowedForView", new object[]
            {
                "EditItem"
            }));
        }
コード例 #8
0
        public void NonEditableEntitySetDoesNotThrowFromCommitEdit()
        {
            DomainDataSourceView dataView = GetConfigurableView(EntitySetOperations.Add | EntitySetOperations.Remove);
            City newCity = new City {
                Name = "City", StateName = "ST"
            };

            dataView.Add(newCity);

            IEditableCollectionView iecv = ((IEditableCollectionView)dataView);

            iecv.EditItem(newCity);

            // Test is to ensure that no exception is thrown from calling CommitEdit
            iecv.CommitEdit();
        }
コード例 #9
0
ファイル: Window1.xaml.cs プロジェクト: yashbajra/samples
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            if (itemsControl.SelectedItem == null)
            {
                MessageBox.Show("No item is selected");
                return;
            }

            //<SnippetEditItem>
            IEditableCollectionView editableCollectionView =
                itemsControl.Items as IEditableCollectionView;

            // Create a window that prompts the user to edit an item.
            ChangeItemWindow win = new ChangeItemWindow();

            editableCollectionView.EditItem(itemsControl.SelectedItem);
            win.DataContext = itemsControl.SelectedItem;

            // If the user submits the new item, commit the changes.
            // If the user cancels the edits, discard the changes.
            if ((bool)win.ShowDialog())
            {
                editableCollectionView.CommitEdit();
            }
            else
            {
                //<SnippetCancelEdit>
                // If the objects in the collection can discard pending
                // changes, calling IEditableCollectionView.CancelEdit
                // will revert the changes. Otherwise, you must provide
                // your own logic to revert the changes in the object.

                if (!editableCollectionView.CanCancelEdit)
                {
                    // Provide logic to revert changes.
                }

                editableCollectionView.CancelEdit();
                //</SnippetCancelEdit>
            }
            //</SnippetEditItem>
        }
コード例 #10
0
        /// <summary>
        /// Executes when the currently selected item should start its editing mode
        /// (show an editing control eg. TextBox instead of TextBlock).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditChanges(object sender, ExecutedRoutedEventArgs e)
        {
            IEditableCollectionView ecv = lb.Items as IEditableCollectionView;
            object selectedItem         = lb.Items.CurrentItem;

            if (selectedItem != null && !ecv.IsEditingItem)
            {
                ecv.EditItem(selectedItem);

                // invoke focus update at loaded priority so that template swap has time to complete
                Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (ThreadStart) delegate()
                {
                    UIElement container = lb.ItemContainerGenerator.ContainerFromItem(selectedItem) as UIElement;
                    if (container != null)
                    {
                        container.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
                    }
                });
            }
        }
コード例 #11
0
 public void EditItem(object item)
 {
     _collectionView.EditItem(item);
 }
コード例 #12
0
        protected override void DeleteCore()
        {
            // Contains the same references as in SelectedEvents,
            // these references can change when un-doing so keep a snapshot around
            List <Event> previousSelection = new List <Event>(SelectedEvents);

            // Contains instance copies of events, this will be the old data before the do is applied.
            List <Event> eventsCopy = SelectedEvents.Select(d => d.DuckCopy <Event>()).ToList();

            #region Do action

            Action doAction = delegate
            {
                // Get the view source of the events collection
                IEditableCollectionView eventsView = (IEditableCollectionView)EventsViewSource.View;

                foreach (Event calendarevent in SelectedEvents)
                {
                    // Edit the view source
                    eventsView.EditItem(calendarevent);

                    // Move the event to the trash
                    calendarevent.EventFolder = Folders.Trash;
                    ClientState.Current.DataService.Update(calendarevent, "EventFolder");

                    // Let the world know that an event is moved to the trash
                    EventBroker.Publish(AppEvents.UpdateEventState, calendarevent);

                    // Commit the changes to the view
                    eventsView.CommitEdit();
                }
            };

            #endregion

            #region Undo action

            Action undoAction = delegate
            {
                // Walk through all the events in the previous selection
                foreach (Event calendarevent in previousSelection)
                {
                    // Get the origional event from the copied list
                    var oldCalendarEvent = eventsCopy.Single(d => d.InternalEventId == calendarevent.InternalEventId);

                    // Set the folder to the origional folder
                    calendarevent.EventFolder = oldCalendarEvent.EventFolder;

                    // Update the event
                    ClientState.Current.DataService.Update(calendarevent, "EventFolder");

                    // Let the world know that an event is updated
                    EventBroker.Publish(AppEvents.UpdateEventState, calendarevent);
                }

                // We cannot use the IEditableObject appraoch here because the document in question
                // probably might not be in view anymore. So instead we will refresh the whole view.
                EventsViewSource.View.Refresh();
            };

            #endregion

            // Add the do and undo actions to the UndoManager
            ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction));
        }