I looked at your question again, and I think this is what you need.
TextBox txtBox = (TextBox)comboBox.Template.FindName("PART_EditableTextBox", comboBox); if (txtBox == null) return; txtBox.ToolTip = comboBox.ToolTip; //this is locating the DataGrid that contains the textbox DataGrid parent = FindParent<DataGrid>(this); //Get the adorner for the parent AdornerLayer myAdornerLayer = AdornerLayer.GetAdornerLayer(parent); Binding bind = new Binding("IsKeyboardFocused"); bind.Converter = new KeyToVisibilityConverter(); bind.Source = txtBox; bind.Mode = BindingMode.OneWay; PEAdornerControl adorner = new PEAdornerControl(txtBox); adorner.SetBinding(PEAdornerControl.VisibilityProperty, bind);
Parent Search Method:
public T FindParent<T>(DependencyObject obj) where T : DepedencyObject { if (obj == null) return null; DependencyOBject parent = VisualTreeHelper.GetParent(obj); if (parent is T) return parent as T; else return FindParent<T>(parent); }
You may need to set the position of your adorner in the OnRender method, but this should work. However, it is worth considering that if your DataGrid is in another container (for example, a panel, grid, etc.), you may encounter a clipping problem.
The clipping problem is related to the fact that when a container checks the location of its children, it usually does not take into account their decorations. To combat this, you may need to create your own control and override the MeasuerOverride (size) method.
Example:
public class MyPanel : Panel { protected override Size MeasureOverride(Size constraint) { Size toReturn = new Size(); foreach (UIElement child in this.InternalChildren) {
This code is really rude to measure, but should point you in the right direction. Check the documentation page http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.measureoverride.aspx for information on measuring child elements in a panel.
source share