As a general rule of thumb, I use Dependency Properties on anything I
want to bind to that isn't in the view model. If its in the view model
(which is usually oblivious of view stuff like controls and bindings
etc) you need to use the INotifyPropertyChanged interface so that the
Bindings will still be updated. If you are creating custom controls or
putting properties in your view etc then I prefer Dependency
Properties.

So INotifyPropertyChanged on POCO and DP's on everything else.

You can bind to a property without using INotifyPropertyChanged but if
it changes the UI will never be notified. It will behave as if it were
a Mode.OneTime binding.

In case you didn't know binding errors are thrown silently but you can
see them in the Output window when debugging. (you probably knew that)

On Fri, Oct 29, 2010 at 9:16 AM,  <[email protected]> wrote:
> Greg, just for completeness, and to clarify (both for you and myself) my
> intentions so you don’t think I’m completely bonkers....
>
> I’m almost 100% sure you don’t actually “have” to use a Dependency property
> in this scenario - you could either use a DP (as you have now done), OR
> imeplement INotifyPropertyChanged on your Modal Dialog Window. And, if you
> used INotifyPropertyChanged there would indeed be someone listening – i.e.
> the Binding!
>
> I was merely suggesting that there is an inherent overhead in using the DP
> system – you know, the stuff that happens behind the scenes within the WPF
> framework when you call DP.Register and in the change monitoring it does etc
> etc. Although in this scenario this overhead is highly unlikely to make any
> user-perceivable difference to the performance of your dialog, minute
> savings like this are one of the things I generally think about when I code,
> which is why I would probably go with the (relatively cheaper) method of
> implementing INotifyPropertyChanged on the Dialog and firing the
> PropertyChanged event as appropriate (thereby causing the binding to
> refresh) in most cases. If I needed to do something more advanced with a
> bound property, say animate it or something like that, then I would most
> certainly use a DP over a regular property.
>
> Hopefully that clarifies and helps,
> Dan.
>
> From: Greg Keogh
> Sent: Friday, October 29, 2010 11:53 AM
> To: 'ozWPF'
> Subject: RE: Dialog OK/Cancel binding
>
>
> OK chaps, I did have to use a dependency property, and I had to get the
> Binding XAML correct. I have this code and XAML
>
>
>
> public static readonly DependencyProperty IsDirtyProperty =
> DependencyProperty.Register("IsDirty", typeof(bool),
> typeof(SettingsWindow));
>
> public bool IsDirty
> {
>     get { return (bool)GetValue(IsDirtyProperty); }
>     set { SetValue(IsDirtyProperty, value); }
> }
>
>
>
> <Button x:Name="btnSettingsOK" IsEnabled="{Binding
> ElementName=WinSettings,Path=IsDirty}" ... />
>
> -or-
>
> <Button x:Name=" btnSettingsOK " IsEnabled="{Binding IsDirty,
> ElementName=WinSettings}" ... />
>
>
>
> Both Binding statements work. I can’t decide which feels more natural. There
> is no need to implement INotifyPropertyChanged as no one is listening to
> this modal dialog window.
>
>
>
> I printed off a WPF Binding Cheat Sheet.
>
>
>
> Greg
>
> ________________________________
> _______________________________________________
> ozwpf mailing list
> [email protected]
> http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
>
> _______________________________________________
> ozwpf mailing list
> [email protected]
> http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
>
>
_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to