gpt4 book ai didi

WPF控件的TabItem可见性复选框

转载 作者:行者123 更新时间:2023-12-04 04:44:54 25 4
gpt4 key购买 nike

我在看:
Visibility Binding using DependencyProperty


http://msdn.microsoft.com/en-us/library/system.windows.controls.booleantovisibilityconverter.aspx
http://www.vistax64.com/avalon/240-no-checkbox-checkedchanged.html
http://geekswithblogs.net/thibbard/archive/2007/12/10/wpf---showhide-element-based-on-checkbox.checked.aspx

我有一些标签,希望通过复选框控制其可见性
IE。

        <TabItem Header="Preferences" Name="tabItem4"></TabItem>

理想情况下,我会做
        <TabItem Header="Preferences" Name="tabItem4">
<DataTrigger Binding="{Binding ElementName=myCheckBox, Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="True" />
</DataTrigger>

</TabItem>

或某些类似的语法,但这不是正确的语法。最简单/正确的语法是什么?

最佳答案

您可以使用内置的BooleanToVisibilityConverter。这是一个工作示例:

<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可见性复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6990982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com