I generally declare my dependency property as normal, then bind to it from the 
UserControl itself. So let’s say you had a real DP called TitleText, I’d do 
something like:

<UserControl ... x:Name=”me”>
    <TextBlock Text=”{Binding TitleText,ElementName=me}” />


... so now the owner of the UserControl can set TitleText and it will be 
reflected by the child control.

Matt

From: Greg Keogh 
Sent: Friday, October 28, 2011 3:34 PM
To: 'ozWPF' 
Subject: Child controls as dependency properties

I have a UserControl which contains children labels, buttons and text boxes. I 
need to expose the properties of the child controls as dependency properties of 
the parent. Like this naive and incorrect code:

 

public string TitleText    // I want this to be a dependency property

{

    get { return childLabel.Text; }

    set { chidlLabel.Text = value; }

}

 

I’ve searched and searched, but can’t find a single example of there anyone 
does this. They talk about it, but no one supplies any example. I’ve fiddled 
with code but I can’t figure out how to alter the standard DP coding pattern to 
override the getter and setter. Does anyone know the trick?

 

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

Reply via email to