Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
105
How to access the Textbox that's inside a XamComboEditor
posted

How can I get access to the TextBox inside the XamComboEditor from the code behind?

I've built a CustomWindowsComboBox to add a "RestrictToList" property that can be used even when the ComboBox IsEditable.  I really like the full type ahead behavior you get in the ComboBox when "IsEditable" is set to true, but I still want to restrict selection to only items on the list.  The behavior is all implemented in a class (no xaml).  I use

private TextBox EditableTextBox { get { return ((TextBox)GetTemplateChild("PART_EditableTextBox")); } }

to get access to the TextBox that's inside the ComboBox, and I hook into the KeyDown, KeyUp, and SelectionChanged events.  Having access to the TextBox allows me to adjust the user input to insure they only enter text that exists on the ComboBox's list.

This CustomWindowsComboBox class works great being based on a Window's ComboBox and the GetTemplateChild method on the Window's ComboBox does properly return the TextBox.  Now I'm trying to implement the same behavior for a XamComboEditor so I can use it in a XamDataPresenter.  The problem I'm having is

GetTemplateChild("PART_EditableTextBox")

always returns null when trying to access the TextBox inside the XamComboEditor. 

Help!!!  :)