列表视图重复按钮高度和宽度自定义

时间:2014-01-29 06:53:37

标签: c# wpf

我正在尝试在WPF中为listview控件的滚动条应用样式。 我想改变重复按钮的高度和宽度。 我该如何配置呢。

我是WPF的新手,任何人都可以帮助我解决这个问题。

先谢谢。

2 个答案:

答案 0 :(得分:0)

您需要修改默认的ScrollBar控件模板。从here复制粘贴默认样式,并根据需要修改“Horizo​​ntalIncrementTemplate”和“VerticalIncrementTemplate”XAML(特别是在您的情况下,请查看修改Path元素的高度/宽度)。

或者,您也可以使用Blend修改控件模板,您可以更轻松地找到它们。

答案 1 :(得分:0)

试试这个

     <ListView>
        <ListView.Style>
            <Style TargetType="ListView">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListView">
                            <ScrollViewer>
                                <ScrollViewer.Style>
                                    <Style TargetType="ScrollViewer">
                                        <Setter Property="OverridesDefaultStyle" Value="True"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ScrollViewer">
                                                    <!--Grid used for displaying listview item(ScrollContentPresenter Grid.ColumnSpan="2") and vertical scrollviwer(Grid Column="1")-->
                                                    <Grid>
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="Auto"/>
                                                            <ColumnDefinition/>
                                                        </Grid.ColumnDefinitions>
                                                        <Grid.RowDefinitions>
                                                            <RowDefinition/>
                                                            <RowDefinition Height="Auto"/>
                                                        </Grid.RowDefinitions>
                                                        <!--Listview item will display in ScrollContentPresenter-->
                                                        <ScrollContentPresenter Grid.ColumnSpan="2"/>
                                                        <!--Vertical Scrollviwer style-->
                                                        <ScrollBar Name="PART_VerticalScrollBar" Grid.Column="1" HorizontalAlignment="Right"  Grid.RowSpan="2" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}">
                                                            <ScrollBar.Style>
                                                                <Style TargetType="ScrollBar">
                                                                    <Setter Property="Template">
                                                                        <Setter.Value>
                                                                            <ControlTemplate TargetType="ScrollBar">
                                                                                <!--you can change height and width of below repeat button -->
                                                                                <Grid Background="Green">
                                                                                    <Grid.RowDefinitions>
                                                                                        <RowDefinition MaxHeight="18"/>
                                                                                        <RowDefinition Height="0.00001*"/>
                                                                                        <RowDefinition MaxHeight="18"/>
                                                                                    </Grid.RowDefinitions>
                                                                                    <Border Grid.RowSpan="3" CornerRadius="2" Background="#F0F0F0" />
                                                                                    <RepeatButton Grid.Row="0" Height="0" Command="ScrollBar.LineUpCommand" Content="M 0 4 L 8 4 L 4 0 Z" />
                                                                                    <Track Name="PART_Track"  Grid.RowSpan="3" IsDirectionReversed="true">
                                                                                        <Track.DecreaseRepeatButton>
                                                                                            <RepeatButton Height="0" Command="ScrollBar.PageUpCommand" />
                                                                                        </Track.DecreaseRepeatButton>
                                                                                        <Track.Thumb>
                                                                                            <Thumb Background="LightGray" Margin="2" />
                                                                                        </Track.Thumb>
                                                                                        <Track.IncreaseRepeatButton>
                                                                                            <RepeatButton Height="0" Command="ScrollBar.PageDownCommand" />
                                                                                        </Track.IncreaseRepeatButton>
                                                                                    </Track>
                                                                                    <RepeatButton Grid.Row="3"  Height="0" Command="ScrollBar.LineDownCommand" Content="M 0 0 L 4 4 L 8 0 Z"/>
                                                                                </Grid>
                                                                            </ControlTemplate>
                                                                        </Setter.Value>
                                                                    </Setter>
                                                                </Style>
                                                            </ScrollBar.Style>
                                                        </ScrollBar>
                                                        <!--similarly you can customize for horizontal scrollviwer-->
                                                        <ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="1" Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ScrollViewer.Style>
                                <ItemsPresenter></ItemsPresenter>
                            </ScrollViewer>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ListView.Style>
    </ListView>

有关详细信息visit