2015-06-02 1 views
4

Я создал базовое приложение WPF для Windows Desktop. В MainWindow, я добавил следующее, как тело окна:SmallChange в XAML ScrollViewer ControlTemplate не имеет эффекта

<ScrollViewer Template="{DynamicResource ScrollViewerControlTemplate1}"> 
     <ScrollViewer.Resources> 
      <ControlTemplate x:Key="ScrollViewerControlTemplate1" TargetType="{x:Type ScrollViewer}"> 
       <Grid x:Name="Grid" Background="{TemplateBinding Background}"> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*"/> 
         <ColumnDefinition Width="Auto"/> 
        </Grid.ColumnDefinitions> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="*"/> 
         <RowDefinition Height="Auto"/> 
        </Grid.RowDefinitions> 
        <Rectangle x:Name="Corner" Grid.Column="1" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Grid.Row="1"/> 
        <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" Margin="{TemplateBinding Padding}" Grid.Row="0"/> 
        <ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Grid.Row="0" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}" SmallChange="40000"/> 
        <ScrollBar x:Name="PART_HorizontalScrollBar" AutomationProperties.AutomationId="HorizontalScrollBar" Cursor="Arrow" Grid.Column="0" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0" Orientation="Horizontal" Grid.Row="1" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/> 
       </Grid> 
      </ControlTemplate> 
     </ScrollViewer.Resources> 
     <Grid Margin="20"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="300"/> 
       <RowDefinition Height="300"/> 
       <RowDefinition Height="300"/> 
       <RowDefinition Height="300"/> 
       <RowDefinition Height="300"/> 
      </Grid.RowDefinitions> 

      <Border Grid.Row="0" Background="SteelBlue"/> 
      <Border Grid.Row="1" Background="Peru"/> 
      <Border Grid.Row="2" Background="Goldenrod"/> 
      <Border Grid.Row="3" Background="Tomato"/> 
      <Border Grid.Row="4" Background="IndianRed"/> 
     </Grid> 

    </ScrollViewer> 

Вы заметите, что на PART_VerticalScrollbar, я задал SmallChange = «40000» (сколь угодно большое число). Тем не менее, когда я нажимаю стрелки вверх/вниз на полосе прокрутки, он делает то же самое очень маленькое изменение, как и до того, как я установил SmallChange на что угодно.

Я читал документацию несколько раз и не могу понять, почему это не влияет на количество прокрутки ScrollViewer. Есть идеи?

Обратите внимание, что я могу изменить шаблон ScrollBar и изменить эту команду, чтобы эти кнопки вызывали кнопки Scrollbar.PageUpCommand, а не Scrollbar.LineUpCommand, но в конечном итоге я хотел бы иметь более тонкий контроль над прокруткой, чем полная страница.

ответ

0

Я подозреваю, что ваш пользовательский шаблон управления не используется из-за того, как вы ссылаетесь на него. Я хотел бы изменить XAML к этому:

<ScrollViewer> 
    <ScrollViewer.Template> 
     <ControlTemplate TargetType="{x:Type ScrollViewer}"> 
      <Grid ...> 
       ... 
      </Grid> 
     </ControlTemplate> 
    </ScrollViewer.Template> 

    ... ScrollViewer content goes here 

</ScrollViewer> 

В принципе, установить шаблон элемента управления непосредственно, а не с помощью динамического ресурса.

Смежные вопросы