Ted12893

Suppose that I have a Button which foreground color is bound to a property in an object, and let's say that this button has it's "Click" event hooked up to a function. Actually let's say we have 5 buttons like this (all bound to different properties) but with the "Click" event connected to the same event.

This event handler actually opens up a Color Selection Dialog. When the user presses the OK button in that Color Selection Dialog I want to update the button's color with this new value, but here comes my problem... i want to retain the binding... how can I set the color of the button and have that value propagated back to the binding source (I know which button it is since that is passed into the Click event handler)

Sure I can retrieve the Binding Expression of that Button's Foreground Property, and then get the "Path" which holds the name of the Property that it's bound to. But this is only a string, so I guess I have to use some reflection to actually get hold of the Binding Source property.... sounds cumbersome.... there must be a simpler way... or !

Or am I going about this in a totally odd way Any hints



Re: Windows Presentation Foundation (WPF) Manual update of value in binding target without detaching the binding...

Yi-Lun Luo - MSFT

Hello, you can try to update the binding source. You mentioned the Foreground is bound to a property in an object. So you can make the property a DependencyProperty, or make your object implement INotifyPropertyChanged interface. Now when you update this property, the binding target will update automatically.