从复选框WPF控件TabItem的知名度 [英] WPF Control TabItem visibility from a checkbox
问题描述
我看了看:
<一href=\"http://stackoverflow.com/questions/3560683/visibility-binding-using-dependencyproperty\">Visibility使用绑定的DependencyProperty
和
<一href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter.aspx\">http://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter.aspx
http://www.vistax64.com/avalon/240-no-checkbox-checkedchanged.html
<一href=\"http://geekswithblogs.net/thibbard/archive/2007/12/10/wpf---showhide-element-based-on-checkbox.checked.aspx\">http://geekswithblogs.net/thibbard/archive/2007/12/10/wpf---showhide-element-based-on-checkbox.checked.aspx
我有一些标签我想从一个复选框控制自己的知名度
即。
I have some tabs I want to control their visibility from a checkbox i.e.
<TabItem Header="Preferences" Name="tabItem4"></TabItem>
在理想情况下,我会做
Ideally I would do
<TabItem Header="Preferences" Name="tabItem4">
<DataTrigger Binding="{Binding ElementName=myCheckBox, Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="True" />
</DataTrigger>
</TabItem>
或一些这样的,但是这是不正确的语法。什么是最简单的/正确的语法?
or some such but that is not correct syntax. What is easiest/correct syntax?
推荐答案
您可以使用内置的<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter.aspx\">BooleanToVisibilityConverter.这里的工作示例:
You can use the built-in BooleanToVisibilityConverter. Here's a working sample:
<Window x:Class="WpfApplication16.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfApplication16"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<BooleanToVisibilityConverter x:Key="b2v" />
</Window.Resources>
<StackPanel>
<CheckBox x:Name="chk" Content="Show There" />
<TabControl>
<TabItem Header="Hello" />
<TabItem Header="There" Visibility="{Binding IsChecked,ElementName=chk,Converter={StaticResource b2v}}" />
<TabItem Header="World" />
</TabControl>
</StackPanel>
</Window>
这篇关于从复选框WPF控件TabItem的知名度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!