2009-03-16 3 views
2

permet de dire que j'ai une zone de liste avec de nombreux articles de sorte qu'un défilement vertical apparaît, mais j'ai caché la barre de défilement avecWPF défilement Listbox vers le bas

ScrollViewer.VerticalScrollBarVisibility="Hidden" 

Est-il possible que je peux ajouter un bouton qui serait défiler vers le bas pour moi? iv essayé d'ajouter

Command="ScrollBar.LineDownCommand" 

à un bouton mais cela n'a eu aucun effet.

Répondre

4

Vous devez indiquer à WPF où commencer la recherche du gestionnaire de commandes. Sans le dire, il va commencer à regarder à partir du Button et ne trouve rien qui gère le LineDownCommand. Malheureusement, le paramétrer sur le ListBox ne suffira pas car le ScrollViewer est à l'intérieur de le ListBox dans le cadre de son modèle, donc WPF ne le trouvera toujours pas.

Réglage à l'un des ListBoxItem s est ringardes, mais fonctionne:

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

Une meilleure façon de le faire serait soit re-modèle le ListBox et coller le Button à l'intérieur du modèle, ou câblez le CommandTarget dans le code-behind.

Questions connexes