1

だから私はアイテムを含むリストを持っています。現在、それらは写真のサムネイルです。このリストをコードビハインドの変更リストにバインドしたかったので、リストボックスを使用しました。しかし、私はこの箱が水平に流れる必要がありました。したがって、StackPanelとしてスタイル設定されます。最後に、スクロールバーではなく、ボタンでスクロールを制御したいと思います。それは機能しない部分ですここにコードサンプルがあります:

<UserControl x:Class="TestBench.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<UserControl.Resources>

    <Style x:Key="StackHorz" TargetType="ListBox">
        <Style.Setters>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Background="AliceBlue" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <ScrollViewer BorderBrush="DarkGreen" BorderThickness="2" VerticalScrollBarVisibility="Disabled"  HorizontalScrollBarVisibility="Disabled">
                            <ItemsPresenter />
                        </ScrollViewer>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>

</UserControl.Resources>

<Grid x:Name="LayoutRoot" Background="White">
    <Button x:Name="_Next" Content="NEXT" Height="20" Width="40" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
    <Button x:Name="_Prev" Content="PREV" Height="20" Width="40" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
    <ListBox x:Name="TestList" Height="100" Width="800" VerticalAlignment="Top">
        ...Insert ListItems...
    </ListBox>
</Grid>

この例では、リストボックスはバインドされていませんが、ItemsSource ={BindingContent}を設定できる必要があります。私が試した背後のコードは:

namespace TestBench

{パブリック部分クラスMainPage:UserControl {public MainPage(){InitializeComponent();

        TestList.Style = this.Resources["StackHorzTop"] as Style;
        _Next.Click += new RoutedEventHandler(_Next_Click);
        _Prev.Click += new RoutedEventHandler(_Prev_Click);
    }

    void _Prev_Click(object sender, RoutedEventArgs e)
    {
        TestList.ScrollIntoView(TestList.Items[0]);
    }

    void _Next_Click(object sender, RoutedEventArgs e)
    {
        TestList.ScrollIntoView(TestList.Items[TestList.Items.Count - 1]);
    }
}

}

しかし、ScrollIntoViewは何もしません。また、リストボックスのVisualTreeHelper.GetChild()としてScrollViewerを取得しようとしましたが、ScrollToHorizo​​ntalOffset()を使用してそこでスクロールしても何も起こりません。

私はそれが物事を設定する奇妙な方法であることを知っていますが、私は3つの機能すべて(バインド、水平方向、ボタンスクロール付きのスクロールバーなし)が必要です。誰かが私がこれでどこが間違っているのか知っていますか?

前もって感謝します、

チャート。

4

1 に答える 1

0

リストボックスをScrollViewerに入れて、スクロールバーが表示されないように(ボタンのみ)、ScrollViewerのスタイルを設定してみてください。

ScrollViewerのテンプレート化可能なパーツの詳細については、こちらをご覧ください

于 2010-10-26T06:39:26.257 に答える