无法在WPF中完全设置ListBox/Scrollviewer的样式 [英] Can't fully style a ListBox/Scrollviewer in WPF

查看:86
本文介绍了无法在WPF中完全设置ListBox/Scrollviewer的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是我们使用标准ControlTemplates创建的自定义滚动条,但是当我将其应用于ListBox时,右下角有一个角,我找不到任何替代方法.

I'm using custom Scrollbars we created using standard ControlTemplates, however when I apply them to a ListBox there is a corner in the bottom right which I am unable to find any way to override.

不幸的是,直到获得更多积分,我才能发布图片.但是我指的是当垂直和水平滚动条都出现时,在右下角有一个白色的空间,我无法绕过它.

Unfortunately I can't post a picture until I get more points. But the corner I'm referring to is when both a vertical and horizontal scrollbar appear, there is a space in the bottom right that is filled with an off-white color that I am unable to ovrerride

推荐答案

这是我使用Blend为ScrollViewer获取的模板代码的一部分.我在右下角添加了一个矩形并将填充"设置为红色.您可以用相同的方式设置其样式,也可以使用Grid.RowSpan ="2"(用于VerticalScrollBar(第一个))或Grid.ColumnSpan ="2"(用于Horizo​​ntalScrollBar(第二个))来扩展ScrollBar之一以覆盖空间. /p>

this is the part of the template code i got for ScrollViewer using Blend. I added a Rectangle in the bottom right corner and set the Fill to Red. You can style it in the same way or you can expand one of the ScrollBar to cover the space using Grid.RowSpan="2" for VerticalScrollBar(first one) or Grid.ColumnSpan="2" for HorizontalScrollBar(second one).

<Style TargetType="{x:Type ScrollViewer}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ScrollContentPresenter Grid.Column="0"/>
                    <ScrollBar Name="PART_VerticalScrollBar" Grid.Row="0" Grid.Column="1" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                    <ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                    <Rectangle Grid.Row="1" Grid.Column="1" Fill="Red"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

这篇关于无法在WPF中完全设置ListBox/Scrollviewer的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆