This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on http://www.jameschambers.com/.

Monday, May 11, 2009

Getting at the Text of a ComboBox in WPF

I am writing a small wrapper for WPF’s ComboBox and want to hook up (optionally) a delegate that filters the list of items, based on what the user has typed already into the text box portion of the control.

I have achieved this with the help of Mole and the FindName method on the Template object.

TextBox input = ((TextBox)comboBox1.Template.FindName("PART_EditableTextBox",comboBox1));
input.TextChanged += new TextChangedEventHandler(input_TextChanged);

FindName allows us to walk across a templated control and search for a child element by the name we pass in.  This allows us to get at some of the innards for some of the existing controls and, in my case as above, attach to events or check properties and the like.

No comments:

Post a Comment