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