1
我使用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>
咦!我不知道這將需要這麼多的努力:D我認爲有一些財產可以調整項目的權利......我沒有這方面的經驗。讓我探索這個並回到你身邊。同時,如果可能的話,請詳細說明一下我創建面板後應該怎麼做。 –
創建一個自定義的'Panel'並不困難......你只需要實現兩種方法。但是,有很多方法可以達到您所追求的效果。我只是推薦自定義的'Panel'路由,因爲這就是我要做的,因爲它符合你迄今選擇的方法。或者,你可以嘗試用'WrapPanel'替換'ItemsPanelTemplate'中的'StackPanel'並試驗'Panel/ListBox'提供的各種對齊選項。 – Sheridan