/// <summary> /// Programmatically initiate an in-place edit. /// </summary> /// <param name="inPlaceEditableControl">The root control that supports in-place editing.</param> /// <param name="containerOfEditableElement">The container of the specific part of the item to be edited (ItemsControl).</param> /// <param name="itemToEdit">The ViewModel backing containerOfEditableElement.</param> /// <param name="getEditableElement">Function to locate the specific visual for the item being edited.</param> public static void BeginInPlaceEdit(this DependencyObject inPlaceEditableControl, DependencyObject containerOfEditableElement, object itemToEdit, Func <DependencyObject, object> getEditableElement) { if (GetIsEditable(inPlaceEditableControl)) { var itemsContainer = containerOfEditableElement as ItemsControl; if (itemsContainer != null) { var containerVisual = itemsContainer.ItemContainerGenerator.ContainerFromItem(itemToEdit); if ((containerVisual == null) || !StartInPlaceEdit(inPlaceEditableControl, containerVisual, itemToEdit, getEditableElement)) { var statusChangeHandler = new ItemContainerGeneratorStatusChangedHandler(inPlaceEditableControl, itemToEdit, getEditableElement); SetItemContainerGeneratorStatusChangedHandler(inPlaceEditableControl, statusChangeHandler); itemsContainer.ItemContainerGenerator.StatusChanged += statusChangeHandler.OnItemContainerGeneratorStatusChanged; } } } }
private static void SetItemContainerGeneratorStatusChangedHandler(DependencyObject control, ItemContainerGeneratorStatusChangedHandler statusChangedHandler) { control.SetValue(ItemContainerGeneratorStatusChangedHandlerProperty, statusChangedHandler); }