public static DataGrid GetParentDatagrid(UIElement element)
        {
            UIElement childElement;      //element from which to start the tree navigation, looking for a Datagrid parent

            if (element is ComboBoxItem) //since ComboBoxItem.Parent is null, we must pass through ItemsPresenter in order to get the parent ComboBox
            {
                ItemsPresenter parentItemsPresenter = VisualTreeFinder.FindParentControl <ItemsPresenter>((element as ComboBoxItem));
                ComboBox       combobox             = parentItemsPresenter.TemplatedParent as ComboBox;
                childElement = combobox;
            }
            else
            {
                childElement = element;
            }

            DataGrid parentDatagrid = VisualTreeFinder.FindParentControl <DataGrid>(childElement); //let's see if the new focused element is inside a datagrid

            return(parentDatagrid);
        }
Example #2
0
 private static void GetTargetElement(TextBox sender, out DependencyObject element, out DependencyProperty dp)
 {
     element = null;
     dp      = null;
     if (sender is TextBox)
     {
         if ((sender.Tag as string) == EDOConstants.TAG_UNDOABLE)
         {
             element = sender;
             dp      = TextBox.TextProperty;
         }
         else
         {
             ComboBox combo = VisualTreeFinder.FindParentControl <ComboBox>(sender);
             if (combo != null && (combo.Tag as string) == EDOConstants.TAG_UNDOABLE)
             {
                 element = combo;
                 dp      = ComboBox.TextProperty;
             }
         }
     }
 }