我正在使用wpf listview。当我修复listview的宽度时,会自动显示水平滚动条。
我想改变它的外表。
就像我在中间显示的列表视图一样,两个角都有左右滚动按钮。
我怎么能做到这一点请让我知道它的紧急......
答案 0 :(得分:2)
如果我理解你的要求:
例如,如果您使用的是GridView,并且希望将水平滚动条转换为视图左侧和右侧的按钮,则可以采用以下方式设置样式:
<Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="{x:Type ScrollViewer}">
<Setter Property="Focusable" Value="false"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<DockPanel Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<RepeatButton DockPanel.Dock="Left"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
Command="{x:Static ScrollBar.LineLeftCommand}"
Content="{StaticResource ScrollLeftArrow}"/>
<RepeatButton DockPanel.Dock="Right"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
Command="{x:Static ScrollBar.LineRightCommand}"
Content="{StaticResource ScrollRightArrow}"/>
<ScrollBar DockPanel.Dock="Right"
Name="PART_VerticalScrollBar"
Orientation="Vertical"
Minimum="0.0"
Maximum="{TemplateBinding ScrollableHeight}"
ViewportSize="{TemplateBinding ViewportHeight}"
Value="{Binding Path=VerticalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Cursor="Arrow"/>
<ScrollBar DockPanel.Dock="Bottom"
Name="PART_HorizontalScrollBar"
Visibility="Hidden"
Orientation="Horizontal" />
<DockPanel Margin="{TemplateBinding Padding}">
<ScrollViewer DockPanel.Dock="Top"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden"
Focusable="false">
<GridViewHeaderRowPresenter Margin="2,0,2,0"
Columns="{Binding Path=TemplatedParent.View.Columns,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector,RelativeSource={RelativeSource TemplatedParent}}"
AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu,RelativeSource={RelativeSource TemplatedParent}}"
ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip,RelativeSource={RelativeSource TemplatedParent}}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</ScrollViewer>
<ScrollContentPresenter Name="PART_ScrollContentPresenter"
KeyboardNavigation.DirectionalNavigation="Local"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
CanContentScroll="{TemplateBinding CanContentScroll}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</DockPanel>
</DockPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这样做是将GridView中使用的ScrollViewer模板修改为:
类似的技术适用于ListBox等,除了ScrollViewer模板更简单,因为它不需要处理标题行。
如果你在启用滚动时解释你想要的确切布局(图片会很好),我可能会给你一个更好的答案。它也可能有助于查看您现有的XAML。