Вам нужно сообщить WPF, где следует искать обработчик команд. Не сказав этого, он начнет смотреть с Button
и не найдет ничего, что обрабатывает LineDownCommand
. К сожалению, установить его на ListBox
не будет, потому что ScrollViewer
внутриListBox
как часть его шаблона, поэтому WPF все равно его не найдет.
Установка в одном из ListBoxItem
с является сматываться, но работает:
<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
к коду.