1

私はスクロールビューアコントロールを持っています。そのコーディング

<Window.Resources>        
    <DataTemplate x:Key="listBoxItemTemplate">
        <TextBlock />
    </DataTemplate>
    <ItemsPanelTemplate x:Key="itemsPanelTemplate">
        <VirtualizingStackPanel Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</Window.Resources>
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="0"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <RepeatButton x:Name="LineLeftButton" 
                Grid.Column="0"
                Grid.Row="1"
                Content="&lt;"      
                Command="{x:Static ScrollBar.LineLeftCommand}"      
                CommandTarget="{Binding ElementName=scrollViewer}"/>
    <RepeatButton x:Name="LineRightButton" 
                Grid.Column="2"
                Grid.Row="1"
                Content="&gt;" 
                Command="{x:Static ScrollBar.LineRightCommand}"      
                CommandTarget="{Binding ElementName=scrollViewer}"/>
    <ScrollViewer Grid.Column="1" Grid.Row="1"  x:Name="scrollViewer" 
                  VerticalScrollBarVisibility="Hidden" 
                  HorizontalScrollBarVisibility="Hidden">
        <ListBox Name="lst2"
                 Margin="0,0,0,0"
                 VerticalAlignment="Stretch" 
                 ItemsPanel="{StaticResource itemsPanelTemplate}"/>
    </ScrollViewer>
</Grid>

ここに画像の説明を入力

その最後にデータがない場合、繰り返しボタンを無効にしたい。

つまり、Listbox データをスクロールしていて、最後にその特定の側 (つまり、左、右) にデータがない場合、その側の RepeatButton は無効になります。逆方向にスクロールすると、前述の RepeatButton が有効になります。

ここではグラフ表示を示しています。私はそれが適切に明確にすることができると確信しています。

画像1:

ここに画像の説明を入力

左側にスクロールするデータがないため、左側で RepeatButton が無効になっていることを確認してください。

画像2:

ここに画像の説明を入力

右側にスクロールするデータがないため、右側で RepeatButton が無効になっていることを確認してください。

このタイプのスクロールは、私が達成しようとしているものです。上/下にスクロールしたときにWpfが繰り返しボタンを無効にするのを読みましたが、役に立ちません。

4

1 に答える 1

1

はい、簡単です。

  • ScrollViewerを取り除く
  • ListBoxコンポーネントをサブクラス化し、新しいプロパティCanScrollHorizo​​ntallyLeft/Rightを追加します
  • 次のようなListBoxのScrollBar.Scrollイベントにフックします。<ListBox ScrollBar.Scroll="event_handler" />
  • 検出を追加し、それに応じてプロパティを変更します。

    private void scroll_handler(object sender, ScrollEventArgs e) {
       ScrollBar sb = e.OriginalSource as ScrollBar;
    
       if (sb.Orientation == Orientation.Horizontal)
           return;
    
       if (sb.Value == sb.Maximum) {
           Debug.Print("At the bottom of the list!");
    }
    

    }

あるいは、ScrollViewerはScrollBar.Scrollイベントも公開する可能性があり、新しいプロパティをサブクラス化/作成する必要はありません。YOuは、scroll_handler内でロジックを実行し、コマンドCanExecuteを変更できます。

于 2012-09-18T09:55:56.053 に答える