Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

What's the best way to notify the binding manager that a DependencyObject property have changed

Closed Thread
 
Thread Tools Display Modes
Old 11-17-2006   #1 (permalink)
Pon
Guest


 

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 ?



Old 11-17-2006   #2 (permalink)
J
Guest


 

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

Old 11-17-2006   #3 (permalink)
J
Guest


 

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

Old 11-18-2006   #4 (permalink)
Pon
Guest


 

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
>



Old 11-18-2006   #5 (permalink)
Pon
Guest


 

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
>



Old 11-18-2006   #6 (permalink)
Pon
Guest


 

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
>



Old 11-18-2006   #7 (permalink)
Pon
Guest


 

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
>



Old 11-21-2006   #8 (permalink)
Newbie


  Wolf_Schmidt[MSFT] is offline

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.
Old 11-29-2006   #9 (permalink)
Pon
Guest


 

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.


Old 11-29-2006   #10 (permalink)
Pon
Guest


 

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.


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding to a custom dependency property diffeq Avalon 1 07-02-2007 01:42 PM
Binding a ComboBox to in internal property Keith Patrick Avalon 4 10-04-2006 08:40 AM
Custom Dependency Property and Binding CSkinner Avalon 3 01-10-2006 03:53 PM
DependencyObject.OnPropertyInvalidated() == DependencyObject.OnPropertyChanged()? Jason Dolinger Avalon 5 01-10-2006 03:52 PM
Re: Data binding doesn't work for Property Tag syntax ? Mikhail Avalon 0 01-10-2006 03:51 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50