Easton Ronaldo
Easton Ronaldo

Reputation: 47

Disabled Items Showing in Listbox

I have a ListBox that is bound to a TabControl. Some of the TabItems inside this (TabControl) are hidden/disabled then become visible/enabled when I open a file.

My issue is that these hidden/disabled items are still visible in my ListBox. Can someone help me with regards as to why this is happening?

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>

Upvotes: 0

Views: 671

Answers (1)

grantnz
grantnz

Reputation: 7423

You need to bind the ListBox item visibility to the tabcontrol item visibility

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

Upvotes: 1

Related Questions