Binding a Control inside a User Control to the User Control's Name


  • Hi

    Inside a C++ Metro style app I have a user control which consists of some radio buttons (among other things). Is it possible to bind the radio buttons' GroupName property to the name (or x:name) property which the user control gets inside the page.xaml? What I found out by myself is that there once was a way via "FindAncestor" but this is not longer possible in Metro.

    Simplified code for the page:

            <local:myControl x:Name="uc1" />
            <local:myControl x:Name="uc2" />
            <local:myControl x:Name="uc3" />

    Simplified code for the user control:

            <RadioButton GroupName="myGroup" />
            <RadioButton GroupName="myGroup" />
            <RadioButton GroupName="myGroup" />
    If I do it that way all radio buttons in all user controls have the same GroupName which is not what I want.  Each set of radio buttons should have a unique GroupName.

    Tuesday, March 27, 2012 7:14 AM


  • I think this wouldn't work either because there is not just one userControl so the Name property differs.

    What worked was that:

    <RadioButton GroupName={Binding Source=Parent, Path=x:Name} />
    I wasn't aware of the possibility to do "source=parent" before.

    • Marked as answer by peterGro Wednesday, March 28, 2012 7:23 AM
    Wednesday, March 28, 2012 7:23 AM

All replies