In this situation, I usually do an ancestor lookup in my normal XAML
(i.e views) as Shane says.  I typically only do element name referencing
in control templates.

 

I think it's a matter of personal coding style rather than best
practice.

 

My two cents,

Carl.

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Shane Morris (Automatic Studio)
<[email protected]>
Sent: Friday, 28 October 2011 6:09 PM
To: ozWPF <[email protected]>
Cc: ozWPF <[email protected]>
Subject: Re: Child controls as dependency properties

 

Fair enuf

Shane Morris  |  Automatic Studio  |  [email protected]  |
+61 438 818 888


On 28/10/2011, at 6:49 PM, "Matt Hamilton" <[email protected]> wrote:

        Yeah I think that'll work too. Since the name is (for all
intents and purposes) private to the XAML of the UserControl itself, I
usually do it this way just so the bindings are a bit more readable. I
don't know if there's a perf benefit one way or the other.

         

        From: Shane Morris (Automatic Studio)
<mailto:[email protected]>  

        Sent: Friday, October 28, 2011 6:42 PM

        To: ozWPF <mailto:[email protected]>  

        Cc: ozWPF <mailto:[email protected]>  

        Subject: Re: Child controls as dependency properties

         

        You couldn't use an ancestor/relative source binding to find the
parent UC, thus Avoiding having to give the UC a specific name?

         

        Shane

        
        
        Shane Morris  |  Automatic Studio  |
[email protected]  |  +61 438 818 888

        
        On 28/10/2011, at 5:35 PM, "Greg Keogh" <[email protected]> wrote:

                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.

                 

                 

                Thanks Matt ... fabulous! I stared at this code for some
time before I realised what was happening. I didn't think of doing it
this way around. You make a typical DP for TitleText then bind the child
control to "its own control". This works, but I have to x:Name the
<UserControl> and bind use that name as the ElementName exactly as you
say.

                 

                Cheers, 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


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

_______________________________________________ 
ozwpf mailing list 
[email protected] 
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf 

________________________________________________________________________
_______ 

This email has been scanned by the Bankwest Email Security System. 
________________________________________________________________________
_______ 

_______________________________________________________________________________
Unencrypted electronic mail is not secure and may not be authentic.
If you have any doubts as to the contents please telephone to confirm.

This electronic transmission including any attachments is intended only
for those to whom it is addressed. It may contain copyright material or
information that is confidential, privileged or exempt from disclosure by law.
Any claim to privilege is not waived or lost by reason of mistaken transmission
of this information. If you are not the intended recipient you must not
distribute or copy this transmission and should please notify the sender.
Your costs for doing this will be reimbursed by the sender.

We do not accept liability in connection with computer virus, data corruption,
delay, interruption, unauthorised access or unauthorised amendment.
_______________________________________________________________________________


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to