1

コントロールを使用して、XAML でブレッドクラムを作成しましたListBox。それはうまく機能します。ただし、あまりにも多くのアイテムを追加して表示しようとすると、当然、それらの一部しか表示されません。右側の要素が表示されるまで、左側のアイテムをどうにかして非表示にしたいと考えています。理想的には、空き領域 (右側) も残しておく必要があります。これどうやってするの?

                <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>
4

1 に答える 1

1

Panelのカスタムを作成する必要がある場合がありますListBox.ItemsPanelTemplate。必要な機能は、この方法で非常に簡単に作成できます。基本的に、各ブレッドクラムをレンダリング時に測定し、適合するもののみを表示できるからです。

まだこれを経験していない場合でも、後回しにしないでください... カスタムPanels でいくつかの素晴らしいことを達成できます。必要な場合に役立つ記事を次に示します。

パネルの概要 (MSDN)

WPF でカスタム レイアウト パネルを作成する方法

WPF でのカスタム パネルの作成

于 2013-07-22T09:29:13.717 に答える