![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | What's the best way to notify the binding manager that a DependencyObject property have changed Hi everybody, Let say that we have a property of a dependecyobject that is readonly (calculated upon other properties). Let also say this property could not be a dependency property but a "normal" property. What's the best way to notify the binding manager that this property have changed ? I know the NotifyPropertyChanged event but i was surprised to see that the corresponding interface is not implemented by DependencyObject. That lets me think there may be "a more wpf style way" to do that. Am I wrong ? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: What's the best way to notify the binding manager that a DependencyObject property have changed Hello, there is a method documented in the Windows SDK, that implies implementing the INotifyPropertyChanged interface. There is a single event here, PropertyChanged. And I quote: "Inherit from INotifyPropertyChanged. Declare a PropertyChanged event, represented by a PropertyChangedEventHandler delegate. Raise the PropertyChanged event whenever a property changes. Conventionally, you raise this event in a private method named NotifyPropertyChanged. When you raise the event, pass it a PropertyChangedEventArgs object, initialized with the name of the property that has changed. The UI element is then automatically updated with the current value of the bound property. " If I understanded correctly that is what you want. All the best, Andrei Iacob |
My System Specs![]() |
| | #3 (permalink) |
| | Re: What's the best way to notify the binding manager that a DependencyObject property have changed That's more or less what i've done. So i will consider that's the best way to do that. Thanx Andrei. "J" <iacobandrei@gmail.com> a écrit dans le message de news: 1163750324.644595.239580@e3g2000cwe.googlegroups.com... > Hello, > there is a method documented in the Windows SDK, that implies > implementing the INotifyPropertyChanged interface. There is a single > event here, PropertyChanged. > And I quote: > "Inherit from INotifyPropertyChanged. > > Declare a PropertyChanged event, represented by a > PropertyChangedEventHandler delegate. > > Raise the PropertyChanged event whenever a property changes. > Conventionally, you raise this event in a private method named > NotifyPropertyChanged. > > When you raise the event, pass it a PropertyChangedEventArgs object, > initialized with the name of the property that has changed. The UI > element is then automatically updated with the current value of the > bound property. > " > > If I understanded correctly that is what you want. > > All the best, > > Andrei Iacob > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: What's the best way to notify the binding manager that a DependencyObject property have changed I wrote the documentation a bit further. WPF offers an explicit way of defining readonly dependency properties using the DependencyPropertyKey class. "J" <iacobandrei@gmail.com> a écrit dans le message de news: 1163750324.644595.239580@e3g2000cwe.googlegroups.com... > Hello, > there is a method documented in the Windows SDK, that implies > implementing the INotifyPropertyChanged interface. There is a single > event here, PropertyChanged. > And I quote: > "Inherit from INotifyPropertyChanged. > > Declare a PropertyChanged event, represented by a > PropertyChangedEventHandler delegate. > > Raise the PropertyChanged event whenever a property changes. > Conventionally, you raise this event in a private method named > NotifyPropertyChanged. > > When you raise the event, pass it a PropertyChangedEventArgs object, > initialized with the name of the property that has changed. The UI > element is then automatically updated with the current value of the > bound property. > " > > If I understanded correctly that is what you want. > > All the best, > > Andrei Iacob > |
My System Specs![]() |
| | #5 (permalink) |
| | Notifying a binding target that a binding source has changed value, and the dependency property capabilities for notifying of a changed value, are a bit tangiental. If you are thinking of it from the perspective of the binding TARGET, those concepts are not tangiental, because the dependency property mechanisms are needed in order to update the target value. Thus, you can only bind to a property that is a DP. INotifyPropertyChanged, which tracks the change to the SOURCE, is deliberately more lightweight than a DP, so that it's feasible to use all kinds of existing objects as property value sources with less requirements for modifying the source class or creating a data provider. You are correct that DependencyObject didn't implement that interface for direct binding support of any DP, I believe that was an architecture decision made early on. Your scenario of having a readonly determined property be a dependency property is quite common in the WPF APIs. FrameworkElement.ActualWidth/ActualHeight are a canonical example, as is UIElement.IsFocused. From a UI and styling perspective, being notified of changes to properties is often done within the styles themselves. That doesn't involve binding, at least not directly. What you might do would be to declare a Trigger in the style that keys off the readonly DP, and use Setters to then change the values of other properties (mostly appearance properties, but you could be setting pure state properties of a control too as a side effect, so long as those properties were all DPs). Also, the DP system and the "WPF way" of capturing property change information sometimes relies on the metadata. For instance, DPs that are known to change the appearance of a control will include metadata noting that fact. Within FrameworkElement, there's code that tracks all property changes for layout purposes, that aspect of FrameworkElement is partially responsible for the proper function of the WPF layout/render system as a whole. Again, binding doesn't participate in that functionality directly. So, what's important to your scenario? That it work through binding? Or that it parallels some similar mechanism that perhaps WPF uses to react to property changes between its feature parts? I'm actually crafting a WPFSDK blog topic that deals with this very subject, which might be helpful to you once it's done, but can't promise a timeframe on that. |
My System Specs![]() |
| | #6 (permalink) |
| | Re: What's the best way to notify the binding manager that a DependencyObject property have changed > I'm actually crafting a WPFSDK blog topic that deals with this very > subject, which might be helpful to you once it's done, but can't > promise a timeframe on that. Thanx for your answer. I will wait for that. |
My System Specs![]() |