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!!! :)
Yes. That does works to give me access to the underlying TextBox.
THANKX!!! :)
There's still something else not quite right that's making by Restrict To List logic not work properly, but it'll take a while for me to get a free moment to look into that. :(
You can use the Infragistics GetDescendantFromName utility method
Please try this as your getter:
get { return ((TextBox)Infragistics.Windows.Utilities.GetDescendantFromName(this.ComboBox,"PART_EditableTextBox")); }
Hope this helps.
.