2

私が欲しいもの:くそったれの水平スクロールバーを表示するには。アプリのスタイルスキームの残りの部分に合うように少し編集しますが、あまり多くはありません.

私が持っているもの

現在のリストボックスのコードは次のとおりです。スクロールバーが表示されないことを除いて、すべてが完全に実行されます。あなたは言うかもしれません...「どこにもスクロールビューアーがありません」と言うかもしれませんが、私は多くの場所にスクロールビューアーを挿入しようとしましたが、まだ運がありません.

リストボックスのコード:

<ListBox ItemsSource="{Binding Items}" ItemTemplate="{StaticResource itemsdatatemplate}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" ItemsPanel="{StaticResource HorizontalListBoxTemplate}" ItemContainerStyle="{StaticResource TransparentListBox}" VerticalAlignment="Center" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />

「TransparentListBox」 (選択した背景色を隠すため):

<Style x:Key="TransparentListBox" TargetType="ListBoxItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Grid>
                    <Border x:Name="HoverBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                    <Border x:Name="SelectedBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                        <ContentPresenter></ContentPresenter>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Horizo​​ntal List Box (リストボックスを標準の垂直ではなく水平にします)

<ItemsPanelTemplate x:Key="HorizontalListBoxTemplate">
    <StackPanel Orientation="Horizontal">
    </StackPanel>
</ItemsPanelTemplate>

Datatemplate (実際にアイテムを表示するため)

<DataTemplate x:Key="itemsdatatemplate">
        <local:ListItemControl HorizontalAlignment="Left" VerticalAlignment="Top" DataContext="{Binding}"/>
</DataTemplate>

簡単な追加になる気がしますがよろしくお願いします。

アップデート

これでスクロールバーが表示されるようになりました:

    <Style x:Key="ScrollingListBox" TargetType="ListBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <ScrollViewer HorizontalScrollBarVisibility="Visible">
                            <ItemsPresenter></ItemsPresenter>
                        </ScrollViewer>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

しかし、それらはそれに応じて機能しません。彼らは感じています... 壊れています。ただし、グリッドの静的な幅 (たとえば 300) を定義する場合、ScrollViewer は完全に機能します。現在、私は完全に流動的なレイアウトを持っています (物事がいっぱいになることを意味します)、これはスクロールビューアーには受け入れられませんか?

4

1 に答える 1

0

独自のテンプレートを作成するときは、そこで ScrollViewer を定義し、ContentPresenter の代わりに ItemPresenter を使用する必要があります。

<Style x:Key="TransparentListBox" TargetType="ListBoxItem">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListBoxItem">
                <Grid>
                    <Border x:Name="HoverBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                    <Border x:Name="SelectedBorderBackgroundBrush" BorderThickness="1" Margin="0,0,25,0" Background="Transparent"/>
                        <ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Visible">
                            <ItemsPresenter />
                        </ScrollViewer>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
于 2011-03-23T22:31:38.127 に答える