1

我想更改 ScrollViewer 的 RepeatButton UP 和 DOWN 的大小,以在工业触摸面板上获得可触摸的大小。

如何访问这些属性?

我能够在 ResourceDictionary 中全局更改 ScrollViewer 的大小,如下所示:

<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
<Setter Property="Stylus.IsFlicksEnabled" Value="True" />
<Style.Triggers>
    <Trigger Property="Orientation" Value="Horizontal">
        <Setter Property="Height" Value="{StaticResource widthScrollbarNormal}" />
        <Setter Property="MinHeight" Value="{StaticResource widthScrollbarNormal}" />
    </Trigger>
    <Trigger Property="Orientation" Value="Vertical">
        <Setter Property="Width" Value="{StaticResource widthScrollbarNormal}" />
        <Setter Property="MinWidth" Value="{StaticResource widthScrollbarNormal}" />
    </Trigger>
</Style.Triggers>

但我找不到更改重复按钮大小的方法。

谢谢

4

1 回答 1

0

在您的视图中,如果是 datagrid,请添加此资源:

<DataGrid.Resources>
     <Style TargetType="{x:Type ScrollBarStyle}" BasedOn="{StaticResource ScrollBarStyle}"/>
 </DataGrid.Resources>

然后在样式文件中创建所有这些样式(如果没有,请检查如何创建和使用一个!):(添加正常的,水平和垂直!

普通的:

<!--scroll bar style (normal/large one)-->
    <Style x:Key="ScrollBarStyle" TargetType="{x:Type ScrollBar}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Horizontal">
                <Setter Property="Width" Value="Auto"/>
                <Setter Property="Height" Value="30"/>
                <Setter Property="MinHeight" Value="0"/>
                <Setter Property="Template" Value="{StaticResource HorizontalScrollBar}" />
            </Trigger>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Width" Value="30"/>
                <Setter Property="MinWidth" Value="0"/>
                <Setter Property="Height" Value="Auto" />
                <Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
            </Trigger>
        </Style.Triggers>
    </Style>

对于水平:

 <!--horizontal scrollbar itself template (normal)-->
    <ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid >
            <Grid.ColumnDefinitions>
                <ColumnDefinition MaxWidth="30"/>
                <ColumnDefinition Width="0.00001*"/>
                <ColumnDefinition MaxWidth="30"/>
            </Grid.ColumnDefinitions>
            <Border
                  Grid.ColumnSpan="3"
                  CornerRadius="0" 
                  Background="#F0F0F0" />
            <RepeatButton 
                  Grid.Column="0"                           
                  Style="{StaticResource ScrollBarLineButton}"
                  Width="Auto"
                  Command="ScrollBar.LineLeftCommand"
                  Content="M 4 0 L 4 8 L 0 4 Z" />
            <Track 
                  Name="PART_Track"
                  Grid.Column="1"
                  IsDirectionReversed="False">
                <Track.DecreaseRepeatButton>
                    <RepeatButton 
                          Style="{StaticResource ScrollBarPageButton}"
                          Command="ScrollBar.PageLeftCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb 
                          Style="{StaticResource ScrollBarThumb}" 
                          Margin="1,0,1,0"  
                          Background="{DynamicResource NormalBrush}"
                          BorderBrush="Transparent" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton 
                          Style="{StaticResource ScrollBarPageButton}"
                          Command="ScrollBar.PageRightCommand" />
                </Track.IncreaseRepeatButton>
            </Track>
            <RepeatButton 
                  Grid.Column="3" 
                  Style="{StaticResource ScrollBarLineButton}"
                  Width="Auto"
                  Command="ScrollBar.LineRightCommand"
                  Content="M 0 0 L 4 4 L 0 8 Z"/>
        </Grid>
    </ControlTemplate>

对于垂直:

 <!--vertical scrollbar itself template (normal)-->
    <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition MaxHeight="30"/>
                <RowDefinition Height="0.00001*"/>
                <RowDefinition MaxHeight="30"/>
            </Grid.RowDefinitions>
            <Border
                  Grid.RowSpan="3"
                  CornerRadius="0" 
                  Background="#F0F0F0" />
            <RepeatButton 
                  Grid.Row="0"                           
                  Style="{StaticResource ScrollBarLineButton}"
                  Height="Auto"
                  Command="ScrollBar.LineUpCommand"
                  Content="M 0 4 L 8 4 L 4 0 Z" />
            <Track 
                  Name="PART_Track"
                  Grid.Row="1"
                  IsDirectionReversed="true">
                <Track.DecreaseRepeatButton>
                    <RepeatButton 
                          Style="{StaticResource ScrollBarPageButton}"
                          Command="ScrollBar.PageUpCommand" />
                </Track.DecreaseRepeatButton>
                <Track.Thumb>
                    <Thumb 
                          Style="{StaticResource ScrollBarThumb}" 
                          Margin="0,1,0,1"  
                          Background="{DynamicResource NormalBrush}"
                          BorderBrush="Transparent" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton 
                          Style="{StaticResource ScrollBarPageButton}"
                          Command="ScrollBar.PageDownCommand" />
                </Track.IncreaseRepeatButton>
            </Track>
            <RepeatButton 
                  Grid.Row="3" 
                  Style="{StaticResource ScrollBarLineButton}"
                  Height="Auto"
                  Command="ScrollBar.LineDownCommand"
                  Content="M 0 0 L 4 4 L 8 0 Z"/>
        </Grid>
    </ControlTemplate>
于 2018-11-23T12:28:54.370 回答