根据所选选项卡设置按钮的可见性 [英] Set Visibility of Button depending from selected Tab
本文介绍了根据所选选项卡设置按钮的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Button和一个带有某些选项卡的TabControl。如果选择了第二个选项卡,我想隐藏该按钮。这是我的方法,但是如果单击第二个选项卡,该按钮不会消失。
I have a Button and a TabControl with some Tabs. I want to hide the button, if the second tab is selected. This is my approach, but the button does not disappear if I click on the second tab. What could be wrong?
<Button Content="New" x:Name="NewButton">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding TabMainControl.SelectedIndex}" Value="1">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<TabControl TabStripPlacement="Top" x:Name="TabMainControl">
<TabItem Header="Name" x:Name="NameTab">...</TabItem>
<TabItem Header="Code" x:Name="CodeTab">...</TabItem>
<TabItem Header="Maleware" x:Name="MalewareTab">...</TabItem>
<TabItem Header="Custom" x:Name="CustomTab">...</TabItem>
</TabControl>
推荐答案
因为要绑定到另一个元素的属性在您的应用程序中,您应该使用 Binding.ElementName属性
和路径
像这样:
Because you want to bind to the property of another element in your application you should use Binding.ElementName Property
and Path
like this:
<DataTrigger Binding="{Binding ElementName=TabMainControl, Path=SelectedIndex}" Value="1">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
这篇关于根据所选选项卡设置按钮的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文