1

在我的主窗口 xaml 中,我有两个用户控件和两个RadioButtons. 我希望RadioButtons 控制Visibility用户控件的。
xml摘录:

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

在用户控件中,我有这样的东西:

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

在运行时我收到此错误:
Cannot find source for binding with reference 'ElementName=Window1.radioButton_Tab'

我在看什么?

4

1 回答 1

1

名称 Window1 不在用户控件的上下文中。

你可以使用下面的代码吗?

<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>
于 2009-09-11T17:33:56.270 回答