Reputation: 82341
I have my own custom TextBox class. In part it helps me handle scans from a barcode reader.
Part of what I need for this to work is a way to capture when the value bound to TextProperty changes.
Note: I am not looking for the "TextChanged" event or any kind of event that relates to a key press (except when that key press updates the source).
I need an event that will fire ONLY when the underlying value gets changed, and I need to be able to access it in my TextBox (meaning it can't be in the ViewModel).
Is this possible?
Upvotes: 1
Views: 147
Reputation: 3316
Yes, you can do this:
In your class' constructor:
var dpd = DependencyPropertyDescriptor.FromProperty(YourTextBoxClass.TextProperty, typeof(YourTextBoxClass));
if (dpd != null)
{
dpd.AddValueChanged(this, ThisIsCalledWhenPropertyIsChanged);
}
And then the handler:
private void ThisIsCalledWhenPropertyIsChanged(object sender, EventArgs e) { }
Hope it helps,
Regards
Upvotes: 2