2009-03-16 14 views
2

は、垂直スクロールが起動するように、私は多くの項目でリストボックスを持っていると言うことができますが、私はWPFのリストボックスのスクロールダウン

ScrollViewer.VerticalScrollBarVisibility="Hidden" 

とスクロールバーを非表示になっています私のためにスクロールダウン? iv30は追加しようとしました

Command="ScrollBar.LineDownCommand" 

ボタンには効果がありません。

答えて

4

コマンドハンドラを探す場所をWPFに指示する必要があります。それを伝えることなく、それはButtonから探し始め、LineDownCommandを扱うものは見つけられません。残念ながらScrollViewerの中にあるListBoxがそのテンプレートの一部であるため、ListBoxに設定するだけでは十分ではありません。

ListBoxItem秒の1に設定すると、naffですが、動作します:

<Window x:Class="WpfApplication1.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="300" Width="300"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 

     <ListBox x:Name="_listBox" ScrollViewer.VerticalScrollBarVisibility="Hidden"> 
      <ListBoxItem x:Name="_listBoxItem">One</ListBoxItem> 
      <ListBoxItem>Two</ListBoxItem> 
      <ListBoxItem>Three</ListBoxItem> 
      <ListBoxItem>One</ListBoxItem> 
      <ListBoxItem>Two</ListBoxItem> 
      <ListBoxItem>Three</ListBoxItem> 
      <ListBoxItem>One</ListBoxItem> 
      <ListBoxItem>Two</ListBoxItem> 
      <ListBoxItem>Three</ListBoxItem> 
      <ListBoxItem>One</ListBoxItem> 
      <ListBoxItem>Two</ListBoxItem> 
      <ListBoxItem>Three</ListBoxItem> 
     </ListBox> 
     <Button Grid.Row="1" Command="ScrollBar.LineDownCommand" CommandTarget="{Binding ElementName=_listBoxItem}">Scroll Down</Button> 
    </Grid> 
</Window> 

再テンプレートListBoxのどちらかになると、テンプレート内のButtonスティック、またはになり、これを行うには良い方法コードの後ろにCommandTargetを配線します。

0

私は手動でScrollViewerのスクロールを制御したいアプリケーションを持っていました。基本的には、ScrollViewerへの参照を取得してから、ScrollToHorizo​​ntalOffset()メソッドを使用してスクロールを制御します。以下は、私が使用するプロセスを説明したブログ記事です:

http://www.developingfor.net/wpf/fun-with-the-wpf-scrollviewer.html

http://www.developingfor.net/wpf/more-fun-with-wpf-scrollviewer.html

関連する問題