在我的主窗口xaml中,我有两个用户控件和两个RadioButton
。我希望RadioButton
s控制用户控件的Visibility
xaml摘录:
<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'
我在俯瞰什么?
答案 0 :(得分: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>