为什么我的ScrollViewer的repeatbutton在底部为白色?

时间:2018-11-21 11:37:37

标签: c# .net wpf mvvm

所以我很好奇为什么底部的scrollviewers重复按钮应该是白色的,它应该是透明的,直到我调整了scrollviewer的大小以使其完全适合之前我才注意到这一点,如何将其颜色更改为透明的?

enter image description here

我一直在寻找  样式的RepeatButton部分,并尝试更改background属性,但是那也不起作用,它什么也没做。

我什至试图隐藏它

<RepeatButton x:Name="PageDown"
                                            Command="ScrollBar.PageUpCommand"
                                            Opacity="0"
                                            Focusable="false" 
                                              Visibility="Hidden"/>

但是那也不起作用,它仍然在那里。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">


    <Style x:Key="ScrollBarTrackThumb"
        TargetType="{x:Type Thumb}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Grid x:Name="Grid">
                        <Rectangle HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                Width="Auto"
                                Height="Auto"
                                Fill="Transparent" />
                        <Border x:Name="CornerScrollBarRectangle"
                            CornerRadius="5"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Width="Auto"
                            Height="Auto"
                            Margin="0,1,0,1"
                            Background="{TemplateBinding Background}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Tag"
                                Value="Horizontal">
                            <Setter TargetName="CornerScrollBarRectangle"
                                Property="Width"
                                Value="Auto" />
                            <Setter Property="Background" Value="Transparent"/>
                            <Setter TargetName="CornerScrollBarRectangle"
                                Property="Height"
                                Value="6" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type ScrollBar}">
        <Setter Property="Stylus.IsFlicksEnabled"
            Value="false" />
        <Setter Property="Foreground"
            Value="#ADABAB" />
        <Setter Property="Background"
            Value="Transparent" />
        <Setter Property="Width"
            Value="7" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollBar}">
                    <Grid x:Name="GridRoot"
                        Width="7"
                        Background="{TemplateBinding Background}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="0.00001*" />
                        </Grid.RowDefinitions>
                        <Track x:Name="PART_Track"
                            Grid.Row="0"
                            IsDirectionReversed="true"
                            Focusable="false">
                            <Track.Thumb>
                                <Thumb x:Name="Thumb"
                                    Background="{TemplateBinding Foreground}"
                                    Style="{DynamicResource ScrollBarTrackThumb}" />
                            </Track.Thumb>
                            <Track.IncreaseRepeatButton>
                                <RepeatButton x:Name="PageUp"
                                            Command="ScrollBar.PageDownCommand"
                                            Opacity="0"
                                            Focusable="false"/>
                            </Track.IncreaseRepeatButton>
                            <Track.DecreaseRepeatButton>
                                <RepeatButton x:Name="PageDown"
                                            Command="ScrollBar.PageUpCommand"
                                            Opacity="0"
                                            Focusable="false" />
                            </Track.DecreaseRepeatButton>
                        </Track>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="Thumb"
                                Property="IsMouseOver"
                                Value="true">
                            <Setter Value="{DynamicResource ButtonSelectBrush}"
                                TargetName="Thumb"
                                Property="Background" />
                        </Trigger>
                        <Trigger SourceName="Thumb"
                                Property="IsDragging"
                                Value="true">
                            <Setter Value="{DynamicResource DarkBrush}"
                                TargetName="Thumb"
                                Property="Background" />
                        </Trigger>

                        <Trigger Property="IsEnabled"
                                Value="false">
                            <Setter TargetName="Thumb"
                                Property="Visibility"
                                Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Orientation"
                                Value="Horizontal">
                            <Setter TargetName="GridRoot"
                                Property="LayoutTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="-90" />
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="PART_Track"
                                Property="LayoutTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="-90" />
                                </Setter.Value>
                            </Setter>
                            <Setter Property="Width"
                                Value="Auto" />
                            <Setter Property="Height"
                                Value="8" />
                            <Setter TargetName="Thumb"
                                Property="Tag"
                                Value="Horizontal" />
                            <Setter TargetName="PageDown"
                                Property="Command"
                                Value="ScrollBar.PageLeftCommand" />
                            <Setter TargetName="PageUp"
                                Property="Command"
                                Value="ScrollBar.PageRightCommand" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

还有实际的滚动查看器

<ScrollViewer  Height="380"
                       Margin="10">

            <ListView ItemsSource="{Binding MessageViewModel.Messages}"
                      x:Name="MyListView"
                      Background="Transparent"
                      BorderThickness="0"
                      Height="380">

                <ListView.ItemTemplate>
                    <DataTemplate>
                        <WrapPanel>
                            <TextBlock Text="{Binding Message}"
                                       FontFamily="Consolas"
                                       Foreground="#61d73d"
                                       TextWrapping="Wrap"/>
                        </WrapPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

1 个答案:

答案 0 :(得分:0)

像克劳斯一样,我认为问题不在于您的repeatButton。相反,您可以通过repeatButton看到(白色)背景。

尝试在您的scrollButton后面放置一个红色矩形以查看结果 甚至更好:请使用snoop来检查此类问题。

但是,Clemens是正确的:在listView内而不是外部在scrollviewer中设置样式/模板。