tags:

views:

514

answers:

1

Hello,
In my main window xaml I have two user controls and two radiobuttons. I want the radiobuttons to control the visibility of the user controls.
xaml excerpt:

    <WpfApp2:ViewTree/>

    <WpfApp2:ViewTab/>

    <RadioButton x:Name="radioButton_Tree" GroupName="View"
                 IsChecked="True"> Tree View </RadioButton>

    <RadioButton x:Name="radioButton_Tab" GroupName="View"
                 IsChecked="False" >Tab View</RadioButton>

in the user controls, I have something like this:

Visibility="{Binding IsChecked, 
                     Converter={StaticResource BooleanToVisibilityConverter}, 
                     ElementName=Window1.radioButton_Tree}" >

At run time I get this error:
Cannot find source for binding with reference 'ElementName=Window1.radioButton_Tab'

What am I overlooking?
Thanks.

+1  A: 

The name Window1 is not in the context of user control.

Can you use the code below?

<WpfApp2:ViewTree Visibility="{Binding IsChecked, 
                  Converter={StaticResource BooleanToVisibilityConverter}, 
                  ElementName=radioButton_Tree}" />

<WpfApp2:ViewTab Visibility="{Binding IsChecked, 
                 Converter={StaticResource BooleanToVisibilityConverter}, 
                 ElementName=radioButton_Tab}" />

<RadioButton x:Name="radioButton_Tree" GroupName="View"
             IsChecked="True"> Tree View </RadioButton>

<RadioButton x:Name="radioButton_Tab" GroupName="View"
             IsChecked="False" >Tab View</RadioButton>
siz
Thanks very much.
Number8