我有ListBox
绑定到TabControl
。隐藏/禁用此(TabItems
)中的一些TabControl
,然后在打开文件时变为可见/启用。
我的问题是这些隐藏/禁用的项目仍在我的ListBox中可见。有人可以帮我解释为什么会这样吗?
TabControl XAML
<TabControl Height="Auto" x:Name="tabControl" Width="Auto"
Padding="0" Margin="3" DataContext="{Binding}">
<TabItem Header="StartPage" x:Name="StartTab" Foreground="White" Height="25">
</TabItem>
<TabItem Header="DragDrop" x:Name="DragDropTab" Foreground="White"
Height="25" IsEnabled="False" Visibility="Hidden">
<Image Height="Auto" x:Name="DragImage" Stretch="Fill" Width="Auto" />
</TabItem>
<TabItem Header="Text" x:Name="TextTab" Foreground="White"
Height="25" IsEnabled="False" Visibility="Hidden" >
<Grid>
<cbox:SyntaxHighlightBox Height="Auto" x:Name="HighlightText"
Width="Auto" Text="" AcceptsTab="True" AcceptsReturn="True"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Visible" />
</Grid>
</TabItem>
</TabControl>
ListBox XAML
<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>
答案 0 :(得分:1)
您需要将ListBox项可见性绑定到tabcontrol项可见性
<DataTemplate>
<TextBlock Text="{Binding Header}" Visibility="{Binding Path=Visibility}"/>
</DataTemplate>