cod*_*oop 5 wpf listview scrollbar
我在resourceDictionary中设置滚动条的样式,而没有给它一个键值:
<Style TargetType="{x:Type ScrollBar}">
...
</Style>
Run Code Online (Sandbox Code Playgroud)
Bur由于某种原因只有Scrollbar类型的一个组件受到样式的影响.不是ListView组件的滚动条!
我认为所有滚动条都具有相同的样式,因为我没有在样式定义中使用任何键值!
有任何想法吗?
默认的 WPF 行为是隐式 ScrollBar 样式将应用于 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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3707 次 |
| 最近记录: |