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/.

Tuesday, May 12, 2009

Getting at the Text of a ComboBox in WPF – Part 2

- You all finished?
- Yeup, it compiles!

At the end of the day yesterday I thought I had made a bit of progress with my filtered-combo box. Unfortunately, though it compiles, I’ve found that I can’t get my app loaded and binding to that event at run-time gives me an exception.

However, in looking for a solution, I found the DependencyPropertyDescriptor object, which allows us to access dependency properties from code.  Using this object I can now observe the text for changes and add my event handler as such:

public Window1()
{
InitializeComponent();

DependencyPropertyDescriptor comboText;
comboText = DependencyPropertyDescriptor.FromProperty(ComboBox.TextProperty, typeof(ComboBox));
comboText.AddValueChanged(this, this.ComboTextChanged);
}

private void ComboTextChanged(object sender, EventArgs e)
{
// ...
}

No comments:

Post a Comment