wpf - [WPF] : Styling a scrollbar, 但ListView 滚动条不受样式影响

标签 wpf listview scrollbar

我在 resourceDictionary 中设置滚动条的样式,但没有给它一个键值:

<Style TargetType="{x:Type ScrollBar}">
      ...
</Style>

Bur 由于某种原因,只有 Scrollbar 类型的组件受样式影响。不是 ListView 组件的滚动条!

我认为所有滚动条都具有相同的样式,因为我没有在样式定义中使用任何键值!

有任何想法吗?

最佳答案

默认的 WPF 行为是您的隐式 ScrollBar 样式将应用于 ListBox 中的滚动条。如果这在您的应用程序中没有发生,那么就会有一些东西覆盖了这个默认行为。您是否有应用于 ListBox 的模板?

我的用于证明默认样式行为的测试应用程序如下:

<Window x:Class="TestScrollBarStyle.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">

<Window.Resources>        
    <Style TargetType="ScrollBar">
        <Setter Property="Background" Value="Red" />
    </Style>        
</Window.Resources>   

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>

    <ScrollViewer x:Name="scroll">
        <Rectangle Height="200" />
    </ScrollViewer>

    <ListBox Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Visible">
        <ListBoxItem>Test 1</ListBoxItem>
        <ListBoxItem>Test 2</ListBoxItem>
        <ListBoxItem>Test 3</ListBoxItem>
        <ListBoxItem>Test 4</ListBoxItem>
        <ListBoxItem>Test 5</ListBoxItem>
        <ListBoxItem>Test 6</ListBoxItem>
        <ListBoxItem>Test 7</ListBoxItem>
        <ListBoxItem>Test 8</ListBoxItem>
        <ListBoxItem>Test 9</ListBoxItem>
        <ListBoxItem>Test 10</ListBoxItem>
        <ListBoxItem>Test 11</ListBoxItem>
    </ListBox>

</Grid>

关于wpf - [WPF] : Styling a scrollbar, 但ListView 滚动条不受样式影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2729537/

相关文章:

c# - XPS 编写器因 .Net 4/字体渲染错误而失败?

c# - WPF/Silverlight 风格分析器

.net - 在 ResourceDictionary 中使用 DataTrigger 定义样式,但在 View 中指定 DataTrigger 绑定(bind)路径

java - 可点击图像的 ListView ,无法打开其他 Activity

android - 如何使用自定义 ListView 适配器捕获多个选定的项目数据?

android - ListView 仅在第一次使用 Picasso 加载图像时滞后

javascript - 如何实现 Facebook 聊天垂直滚动条样式?

wpf - MVVM Batch Job处理文件属于ViewModel吗?

html - 你可以在 div 的两个平行边都有滚动条吗?

html - 流体布局中不需要的水平滚动条