恼人的广场,在那里滚动条符合 [英] Annoying Square Where Scrollbars Meet

查看:182
本文介绍了恼人的广场,在那里滚动条符合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ScrollViewer中的应用程序。凡2滚动满足是一个恼人的小方块(见下文图片)我试图摆脱。当我史努比的应用程序,我可以找到它作为一个矩形,但我承担的ScrollViewer它的一部分吗?

我已经搜索和搜索有这方面的信息,但所有我能看到的是建议通过将一些在它的顶部将其隐藏:■

任何人都可以点我在正确的方向进行排序​​呢?

 <控件模板X:关键=Horizo​​ntalScrollBar
        的TargetType ={X:类型滚动条}>
        <电网>
            < Grid.ColumnDefinitions>
                < ColumnDefinition了maxWidth =18/>
                < ColumnDefinition宽度=0.00001 */>
                < ColumnDefinition了maxWidth =18/>
            < /Grid.ColumnDefinitions>
            < BORDER
                Grid.ColumnSpan =3
                CornerRadius =2
                背景=透明/>
            <的RepeatButton
                Grid.Column =0
                风格={的StaticResource ScrollBarLineButton}
                WIDTH =18
                命令=ScrollBar.LineLeftCommand
                内容=M 4 0 L 4 8 L 0 4 Z/>
            <轨道
                NAME =PART_Track
                Grid.Column =1
                IsDirectionReversed =FALSE>
                < Track.DecreaseRepeatButton>
                    <的RepeatButton
                        风格={的StaticResource ScrollBarPageButton}
                        命令=ScrollBar.PageLeftCommand/>
                < /Track.DecreaseRepeatButton>
                < Track.Thumb>
                    <拇指
                        风格={的StaticResource ScrollBarThumb}
                        保证金=0,1,0,1
                        背景={DynamicResource NormalBrush}
                        BorderBrush ={DynamicResource NormalBorderBrush}/>
                < /Track.Thumb>
                < Track.IncreaseRepeatButton>
                    <的RepeatButton
                        风格={的StaticResource ScrollBarPageButton}
                        命令=ScrollBar.PageRightCommand/>
                < /Track.IncreaseRepeatButton>
            < /轨道>
            <的RepeatButton
                Grid.Column =3
                风格={的StaticResource ScrollBarLineButton}
                WIDTH =18
                命令=ScrollBar.LineRightCommand
                内容=M 0 0 L 4 4升0 8 Z/>
        < /网格>
    < /控件模板>
 

解决方案

我只是有完全相同的问题,但发现这个答案在这里对堆栈解决这个问题对我来说:

<一个href="http://stackoverflow.com/questions/1944633/cant-fully-style-a-listbox-scrollviewer-in-wpf">Can't完全风格一个ListBox / ScrollViewer中的WPF

尽管解决方案确实放东西的地方的广场,它在ControlTemplate中进行(在的ScrollViewer ,而不是滚动条)而不是通过一些泡沫胶,把打补丁上的东西的ScrollViewer 控制

上面的方法

不过,我发现,只是省略从该模板完全矩形的定义,恼人的角方只是消失 - 即该地区呈现无论ScrollViewer的背景颜色(其中,在所举的例子,是透明的 - 。和适合我很好,如果你想设置的ScrollViewer背景的颜色,只需设置网格的背景属性)

所以尝试添加到您的资源:

 &LT;风格的TargetType ={X:类型的ScrollViewer}&GT;
    &LT; setter属性=模板&GT;
        &LT; Setter.Value&GT;
            &LT;的ControlTemplate的TargetType ={X:类型的ScrollViewer}&GT;
                &LT;电网&GT;
                    &LT; Grid.ColumnDefinitions&GT;
                        &LT; ColumnDefinition /&GT;
                        &LT; ColumnDefinition宽度=自动/&GT;
                    &LT; /Grid.ColumnDefinitions>
                    &LT; Grid.RowDefinitions&GT;
                        &LT; RowDefinition /&GT;
                        &LT; RowDefinition高度=自动/&GT;
                    &LT; /Grid.RowDefinitions>
                    &所述; ScrollContent presenter Grid.Column =0/&GT;
                    &所述;滚动条X:名称=PART_VerticalScrollBarGrid.Row =0Grid.Column =1值={TemplateBinding VerticalOffset}最大值={TemplateBinding ScrollableHeight}ViewportSize ={TemplateBinding ViewportHeight}能见度= {TemplateBinding ComputedVerticalScrollBarVisibility}/&GT;
                    &LT;滚动条X:名称=PART_Horizo​​ntalScrollBar方向=横向Grid.Row =1Grid.Column =0值={TemplateBinding Horizo​​ntalOffset}最大={TemplateBinding ScrollableWidth}ViewportSize ={TemplateBinding ViewportWidth}能见度={TemplateBinding ComputedHorizo​​ntalScrollBarVisibility}​​/&GT;
                    &所述;! - &所述;矩形Grid.Row =1Grid.Column =1填充=红/&GT  - →;
                &LT; /网格&GT;
            &LT; /控件模板&GT;
        &LT; /Setter.Value>
    &LT; /二传手&GT;
&LT; /样式和GT;
 

I have an app with a ScrollViewer. Where the 2 scrollbars meet is an annoying little square (see img below) I am trying to get rid of. When I "Snoop" the app I can find it as a "Rectangle" but I assume its part of the ScrollViewer?

I have searched and search for any info on this but all I can find are suggestions to hide it by placing something over the top of it :s

Can anyone point me in the right direction to sort this?

<ControlTemplate x:Key="HorizontalScrollBar" 
        TargetType="{x:Type ScrollBar}">
        <Grid >
            <Grid.ColumnDefinitions>
                <ColumnDefinition MaxWidth="18"/>
                <ColumnDefinition Width="0.00001*"/>
                <ColumnDefinition MaxWidth="18"/>
            </Grid.ColumnDefinitions>
            <Border
                Grid.ColumnSpan="3"
                CornerRadius="2" 
                Background="Transparent"   />
            <RepeatButton 
                Grid.Column="0"                           
                Style="{StaticResource ScrollBarLineButton}"
                Width="18"
                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="0,1,0,1"  
                        Background="{DynamicResource NormalBrush}"
                        BorderBrush="{DynamicResource NormalBorderBrush}" />
                </Track.Thumb>
                <Track.IncreaseRepeatButton>
                    <RepeatButton 
                        Style="{StaticResource ScrollBarPageButton}"
                        Command="ScrollBar.PageRightCommand" />
                </Track.IncreaseRepeatButton>
            </Track>
            <RepeatButton 
                Grid.Column="3" 
                Style="{StaticResource ScrollBarLineButton}"
                Width="18"
                Command="ScrollBar.LineRightCommand"
                Content="M 0 0 L 4 4 L 0 8 Z"/>
        </Grid>
    </ControlTemplate>

解决方案

I was just having the exact same problem, but found this answer here on Stack to solve it for me:

Can't fully style a ListBox/Scrollviewer in WPF

Although that solution does put something in place of the square, it's done in the ControlTemplate (of the ScrollViewer, not the ScrollBar) rather than via some bubble-gum-patching approach of putting something on top of the ScrollViewer control.

However, I found that by just omitting the Rectangle definition from that template altogether, the annoying corner square just goes away - i.e. that area takes on whatever the background color of the ScrollViewer is (which, in the example given, is transparent - and that suits me fine. If you want to set the color of the ScrollViewer background, just set the Background property of the Grid).

So try adding this to your Resource:

<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 x:Name="PART_VerticalScrollBar" Grid.Row="0" Grid.Column="1" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                    <ScrollBar x: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>

这篇关于恼人的广场,在那里滚动条符合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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