Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表框中显示的已禁用项目_C#_Wpf_Binding_Listbox - Fatal编程技术网

C# 列表框中显示的已禁用项目

C# 列表框中显示的已禁用项目,c#,wpf,binding,listbox,C#,Wpf,Binding,Listbox,我有一个绑定到选项卡控件的列表框。此(TabControl)中的一些TabItems)被隐藏/禁用,然后在打开文件时变为可见/启用 我的问题是这些隐藏/禁用的项目在我的列表框中仍然可见。有人能帮我解释一下为什么会这样吗 tabcontrolxaml 列表框XAML 您需要将ListBox项可见性绑定到tabcontrol项可见性 <DataTemplate> <TextBlock Text="{Binding Header}" Visibility="{Binding

我有一个绑定到
选项卡控件的
列表框
。此(
TabControl
)中的一些
TabItems
)被隐藏/禁用,然后在打开文件时变为可见/启用

我的问题是这些隐藏/禁用的项目在我的列表框中仍然可见。有人能帮我解释一下为什么会这样吗

tabcontrolxaml



列表框XAML


您需要将ListBox项可见性绑定到tabcontrol项可见性

<DataTemplate>
    <TextBlock Text="{Binding Header}" Visibility="{Binding Path=Visibility}"/>
</DataTemplate>


< /代码>也许您可以显示当前代码,将ListBox的ItEsStand绑定到TabMe控件的TabItIt,这样人们就可以考虑如何最好地添加所需的筛选器了?选项卡是否动态插入/删除?他们是否不断更改其启用/可见状态?当然!为TabControl和ListBox添加了XAML。我的目标是以类似于VisualStudio“解决方案资源管理器”的方式显示打开的项。是的,用户可以单击要隐藏的选项卡项上的“X”,然后只需在project explorer窗口中单击它即可重新启用。已禁用!=不可见(仅供参考,因为您可以互换使用这些术语)。您可能需要将tabitem visibility更改为Collazed以使列表项正常工作(或使用绑定转换器将Hidden映射为Collazed)
<ListBox ItemsSource="{Binding Items, ElementName=tabControl}" 
         x:Name="ShowOpenTabs" >
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}" 
               BasedOn="{StaticResource {x:Type ListBoxItem}}">
            <EventSetter Event="MouseDoubleClick" Handler="OpenOnClick"/>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Header}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
<DataTemplate>
    <TextBlock Text="{Binding Header}" Visibility="{Binding Path=Visibility}"/>
</DataTemplate>