我正在为一个资源字典中的滚动条进行样式设置,而不给它一个键值:
<Style TargetType="{x:Type ScrollBar}">
...
</Style>
但出于某种原因,只有类型为Scrollbar的组件受到样式的影响。而ListView组件的滚动条没有受到影响!
我认为所有滚动条都应该具有相同的样式,因为在样式定义中我没有使用任何键值!
有什么想法吗?
我正在为一个资源字典中的滚动条进行样式设置,而不给它一个键值:
<Style TargetType="{x:Type ScrollBar}">
...
</Style>
但出于某种原因,只有类型为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>