ListBox
我使用控件在我的 XAML 中创建了面包屑。它工作得很好。但是,当我尝试显示添加太多项目时,自然只会显示其中的一些。我想以某种方式隐藏左侧项目,直到右侧元素可见。理想情况下,它也应该留下一些可用空间(右侧)。我怎样才能做到这一点?
<ListBox Height="80" HorizontalAlignment="Stretch" x:Name="breadcrumb"
MinWidth="300" Background="Transparent" BorderThickness="0"
ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Margin="8,0,0,0" Orientation="Horizontal" HorizontalAlignment="Stretch" Background="Transparent">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="#111"/>
<Setter Property="BorderBrush" Value="#AAA"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<StackPanel Orientation="Horizontal" Margin="-8,0,0,0">
<Image Source="Assets/breadcrumb.png" VerticalAlignment="Center" Margin="5,0,0,0"/>
<ContentPresenter />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Stretch">
<TextBlock FontSize="35" Text="{Binding Name}" VerticalAlignment="Center" Padding="5,10"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>