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

Binding to a custom dependency property

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-29-2007   #1 (permalink)
diffeq
Guest


 

Binding to a custom dependency property

When the source's "MyColor" property is changed, the GraphPanel's "AxisColor"
is not changed.

This binding works fine if I use one of GraphPanel's built-in dependency
properties, such as Tag.

-----------------------------------------------

public class MySource : INotifyPropertyChanged
{
....
public SolidColorBrush MyColor {...}
....
}

-----------------------------------------------

<Grid> <!-- DataContext set in code to MySource -->
....
<GraphPanel : DockPanel>
<Binding Path="MyColor">
</GraphPanel>
....
</Grid>

------------------------------------------------

public class GraphPanel
{
....
public static readonly DependencyProperty AxisColorProperty =
DependencyProperty.Register(
"AxisColor",
typeof(SolidColorBrush),
typeof(GraphPanel),
new PropertyMetadata(Brushes.Black));

public SolidColorBrush AxisColor
{
get { return (SolidColorBrush)this.GetValue(AxisColorProperty); }
set { this.SetValue(AxisColorProperty, value); }
}
....
}

My System SpecsSystem Spec
Old 07-02-2007   #2 (permalink)
diffeq
Guest


 

Mystery Solved

I found the following at
http://www.quepublishing.com/article...seqNum=2&rl=1:


WARNING: .NET property wrappers are bypassed at run-time when setting
dependency properties in XAML!

Although the XAML compiler depends on the property wrapper at compile-time,
at run-time WPF calls the underlying GetValue and SetValue methods directly!
Therefore, to maintain parity between setting a property in XAML and
procedural code, it's crucial that property wrappers do not contain any logic
in addition to the GetValue/SetValue calls. If you want to add custom logic,
that's what the registered callbacks are for. All of WPF's built-in property
wrappers abide by this rule, so this warning is for anyone writing a custom
class with its own dependency properties.



"diffeq" wrote:

> When the source's "MyColor" property is changed, the GraphPanel's "AxisColor"
> is not changed.
>
> This binding works fine if I use one of GraphPanel's built-in dependency
> properties, such as Tag.
>
> -----------------------------------------------
>
> public class MySource : INotifyPropertyChanged
> {
> ...
> public SolidColorBrush MyColor {...}
> ...
> }
>
> -----------------------------------------------
>
> <Grid> <!-- DataContext set in code to MySource -->
> ...
> <GraphPanel : DockPanel>
> <Binding Path="MyColor">
> </GraphPanel>
> ...
> </Grid>
>
> ------------------------------------------------
>
> public class GraphPanel
> {
> ...
> public static readonly DependencyProperty AxisColorProperty =
> DependencyProperty.Register(
> "AxisColor",
> typeof(SolidColorBrush),
> typeof(GraphPanel),
> new PropertyMetadata(Brushes.Black));
>
> public SolidColorBrush AxisColor
> {
> get { return (SolidColorBrush)this.GetValue(AxisColorProperty); }
> set { this.SetValue(AxisColorProperty, value); }
> }
> ...
> }

My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Use my custom TypeDescriptor to obtains default Value on property inXAML Property Editor of Visual Studio 2008 azerty Avalon 0 04-14-2008 06:14 AM
WPF: Autogenerate a Private Dependency Property ? Jules Winfield .NET General 4 03-06-2008 09:43 AM
Custom Dependency Property in custom class hierarchy not workingcorrectly?! MueMeister Avalon 0 03-02-2006 06:19 PM
Paragraph.Text? Should there be a dependency property as well? Jason Dolinger Avalon 11 01-31-2006 06:59 AM
Custom Dependency Property and Binding CSkinner Avalon 3 01-10-2006 03:53 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 51