none
滚动条样式问题 RRS feed

  • 问题

  • 我重写了滚动条的样式,半圆角,70%透明度,

    在记录数多时出现滚动条没问题。(图一)

    在记录数不多时,设置ScrollViewer.VerticalScrollBarVisibility="Visible",显示出的滚动条有个灰色的背景(图二)。

    我怎么也去不掉,请问是哪里的问题?

     

    图一

            

    图二


    不见不散
    2011年10月31日 2:17

全部回复

  • 这个问题出在你自己写的样式哪里, 你能分享下你写的样式,让我重现这个问题。


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年11月2日 5:35
    版主
  • listBox代码:

    <ListBox Background="{x:Null}" Style="{DynamicResource ListBoxStyle1}" 

    HorizontalAlignment="Center" VerticalAlignment="Center" 

    Height="110.134" Width="117.332" 

    ScrollViewer.VerticalScrollBarVisibility="Visible">

    <ListBoxItem Content="ListBoxItem"/>

    <ListBoxItem Content="ListBoxItem"/>

    <ListBoxItem Content="ListBoxItem"/>

    <ListBoxItem Content="ListBoxItem"/>

    <ListBoxItem Content="ListBoxItem"/>

    </ListBox>

     

    listBox样式:

    <Style x:Key="ScrollBarStyle1" TargetType="{x:Type ScrollBar}">

    <Setter Property="Background" Value="{StaticResource VerticalScrollBarBackground}"/>

    <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>

    <Setter Property="Stylus.IsFlicksEnabled" Value="false"/>

    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>

    <Setter Property="Width" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>

    <Setter Property="MinWidth" Value="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate TargetType="{x:Type ScrollBar}">

    <Grid x:Name="Bg" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">

    <Grid.RowDefinitions>

    <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>

    <RowDefinition Height="0.00001*"   />

    <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>

    </Grid.RowDefinitions>

    <Rectangle Margin="0" RadiusY="8" RadiusX="8" Opacity="0.5" Grid.RowSpan="3">

    <Rectangle.Effect>

    <DropShadowEffect ShadowDepth="1" Color="#FFE8F3F7" BlurRadius="1"/>

    </Rectangle.Effect>

    <Rectangle.Fill>

    <LinearGradientBrush EndPoint="0.159,0.412" MappingMode="RelativeToBoundingBox" StartPoint="0.03,0.412">

    <GradientStop Color="#FF878787" Offset="0"/>

    <GradientStop Color="#FFB1B1B1" Offset="1"/>

    </LinearGradientBrush>

    </Rectangle.Fill>

    </Rectangle>

    <Rectangle Margin="0" RadiusY="8" RadiusX="8" Opacity="0.5" Grid.RowSpan="3">

    <Rectangle.Fill>

    <LinearGradientBrush EndPoint="0.159,0.412" MappingMode="RelativeToBoundingBox" StartPoint="0.03,0.412">

    <GradientStop Color="#FF9FA3A6" Offset="0"/>

    <GradientStop Color="#FFC9CCD3" Offset="1"/>

    <GradientStop Color="#FFAEB1B6" Offset="0.098"/>

    </LinearGradientBrush>

    </Rectangle.Fill>

    </Rectangle>

    <RepeatButton Command="{x:Static ScrollBar.LineUpCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Style="{DynamicResource RepeatButtonStyleStandard}" Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph="UpArrow"/>

    <Track x:Name="PART_Track" IsDirectionReversed="true" IsEnabled="{TemplateBinding IsMouseOver}" Grid.Row="1"  >

    <Track.DecreaseRepeatButton>

    <RepeatButton  Command="{x:Static ScrollBar.PageUpCommand}" Style="{StaticResource VerticalScrollBarPageButton}"  />

    </Track.DecreaseRepeatButton>

    <Track.IncreaseRepeatButton>

    <RepeatButton x:Name="ButPageDown" Command="{x:Static ScrollBar.PageDownCommand}" Style="{StaticResource VerticalScrollBarPageButton}" Background="{x:Null}"   />

    </Track.IncreaseRepeatButton>

    <Track.Thumb >

    <Thumb   MinHeight="20" Style="{DynamicResource ThumbStyleStandard2}"

    Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph="VerticalGripper"

    HorizontalAlignment="Center"  />

    </Track.Thumb>  

    </Track>  

     

    <RepeatButton Command="{x:Static ScrollBar.LineDownCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Grid.Row="2" Style="{DynamicResource RepeatButtonStyleStandardDown}" Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph="DownArrow"/>

    </Grid>

    <ControlTemplate.Triggers>

    <Trigger Property="IsEnabled" Value="false">

    <Setter Property="Background" TargetName="Bg" Value="{StaticResource ScrollBarDisabledBackground}"/>

    </Trigger>

    </ControlTemplate.Triggers>

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    <Style.Triggers>

    <Trigger Property="Orientation" Value="Horizontal">

    <Setter Property="Width" Value="Auto"/>

    <Setter Property="MinWidth" Value="0"/>

    <Setter Property="Height" Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}"/>

    <Setter Property="MinHeight" Value="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarHeightKey}}"/>

    <Setter Property="Background" Value="{StaticResource HorizontalScrollBarBackground}"/>

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate TargetType="{x:Type ScrollBar}">

    <Grid x:Name="Bg" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">

    <Grid.ColumnDefinitions>

    <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/>

    <ColumnDefinition Width="0.00001*"/>

    <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/>

    </Grid.ColumnDefinitions>

    <RepeatButton Command="{x:Static ScrollBar.LineLeftCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Style="{StaticResource ScrollBarButton}" Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph="LeftArrow"/>

    <Track x:Name="PART_Track" Grid.Column="1" IsEnabled="{TemplateBinding IsMouseOver}">

    <Track.DecreaseRepeatButton>

    <RepeatButton Command="{x:Static ScrollBar.PageLeftCommand}" Style="{StaticResource HorizontalScrollBarPageButton}"/>

    </Track.DecreaseRepeatButton>

    <Track.IncreaseRepeatButton>

    <RepeatButton Command="{x:Static ScrollBar.PageRightCommand}" Style="{StaticResource HorizontalScrollBarPageButton}"/>

    </Track.IncreaseRepeatButton>

    <Track.Thumb>

    <Thumb Style="{StaticResource ScrollBarThumb}" Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph="HorizontalGripper"/>

    </Track.Thumb>

    </Track>

    <RepeatButton Grid.Column="2" Command="{x:Static ScrollBar.LineRightCommand}" IsEnabled="{TemplateBinding IsMouseOver}" Style="{StaticResource ScrollBarButton}" Microsoft_Windows_Themes:ScrollChrome.ScrollGlyph="RightArrow"/>

    </Grid>

    <ControlTemplate.Triggers>

    <Trigger Property="IsEnabled" Value="false">

    <Setter Property="Background" TargetName="Bg" Value="{StaticResource ScrollBarDisabledBackground}"/>

    </Trigger>

    </ControlTemplate.Triggers>

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    </Trigger>

    </Style.Triggers>

    </Style>

     

    <ControlTemplate x:Key="ScrollViewerControlTemplate1" TargetType="{x:Type ScrollViewer}">

    <Grid x:Name="Grid" Background="{TemplateBinding Background}">

    <Grid.ColumnDefinitions>

    <ColumnDefinition Width="*"/>

    <ColumnDefinition Width="Auto" />

    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>

    <RowDefinition Height="*"/>

    <RowDefinition Height="Auto"/>

    </Grid.RowDefinitions>

    <Rectangle x:Name="Corner" Grid.Column="1" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Grid.Row="1"/>

    <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" Margin="{TemplateBinding Padding}" Grid.Row="0"/>

    <ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="0"

    Maximum="{TemplateBinding ScrollableHeight}" 

    Minimum="0" Grid.Row="0"  

    Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" 

    Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" 

    ViewportSize="50" Style="{DynamicResource ScrollBarStyle1}"

    Background="{x:Null}" Width="15" MinWidth="15"  Opacity="0.7"

    SnapsToDevicePixels="True" HorizontalAlignment="Right"/>

    <ScrollBar x:Name="PART_HorizontalScrollBar" AutomationProperties.AutomationId="HorizontalScrollBar" Cursor="Arrow" Grid.Column="0" 

    Maximum="{TemplateBinding ScrollableWidth}"

     

    Minimum="0" Orientation="Horizontal" Grid.Row="1" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}" Style="{DynamicResource ScrollBarStyleHorizontalStandard}" Background="{x:Null}" Opacity="0.7" Height="15" VerticalAlignment="Bottom" Grid.ColumnSpan="2"/>

    </Grid>

    </ControlTemplate>

    <Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}">

    <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>

    <Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>

    <Setter Property="BorderThickness" Value="1"/>

    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>

    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>

    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>

    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>

    <Setter Property="ScrollViewer.PanningMode" Value="Both"/>

     

    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>

    <Setter Property="VerticalContentAlignment" Value="Center"/>

    <Setter Property="Template">

    <Setter.Value>

    <ControlTemplate TargetType="{x:Type ListBox}">

    <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">

    <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}" Template="{DynamicResource ScrollViewerControlTemplate1}" MinHeight="0"  >

    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

    </ScrollViewer>

    </Border>

    <ControlTemplate.Triggers>

    <Trigger Property="IsEnabled" Value="false">

    <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>

    </Trigger>

    <Trigger Property="IsGrouping" Value="true">

    <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>

    </Trigger>

    </ControlTemplate.Triggers>

    </ControlTemplate>

    </Setter.Value>

    </Setter>

    </Style>

     


    不见不散
    2011年11月3日 3:11