2017-02-23 79 views
1

我正在尝试更改水平滚动条的大小和显示。目前滚动条仅在移动列表视图项目时显示。 我需要将它做得更大,并为其添加颜色。我可以使用它的样式吗?XAML更改大小并显示水平滚动条

<ListView x:Name="listview" ScrollViewer.HorizontalScrollBarVisibility="Visible" ItemsSource="{Binding Path=YourCollection}" 
        GotFocus="StackPanel_GotFocus" IsItemClickEnabled="True" ItemClick="ListView_ItemClick" Margin="125,262,125,19"> 
      <ListView.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal" Height="200"/> 
       </ItemsPanelTemplate> 
      </ListView.ItemsPanel> 

      <ListView.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Vertical" Height="200" Width="256"> 
         <StackPanel Orientation="Horizontal"> 
          <Image Source="{Binding Image}" Height="144" Width="256" HorizontalAlignment="Stretch" VerticalAlignment="Top"/> 
         </StackPanel> 
         <StackPanel Orientation="Horizontal"> 
          <TextBlock Text="{Binding Title}" Height="56" Width="256" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/> 
         </StackPanel> 
        </StackPanel> 
       </DataTemplate> 
      </ListView.ItemTemplate> 
     </ListView> 

回答

0

您可以为ListView及其内部的ScrollViewer和ScrollBar创建自定义样式。

你会发现定义为样式覆盖这里:

如果你想改变你的应用程序的所有滚动条,覆盖ScrollBar风格就够了

如果您希望此自定义样式仅适用于您的ListView,则会更棘手。

您将不得不创建一个自定义ScrollBar样式来更改所需的属性。 然后创建一个自定义ScrollViewer样式,它将引用/使用您的自定义ScrollBar样式。 最后,创建一个自定义的ListView样式,它将引用/使用您的自定义ScrollViewer样式。

它看起来如下所示:

的ListView风格:

<Style TargetType="ListView" x:Key="MyListViewStyle"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListView"> 
       <Border> 
        <ScrollViewer x:Name="ScrollViewer" Style={StaticResource myCustomScrollViewerStyle" /> 
       </Border> 
      </ControlTemplate> 
    </Setter> 
</Style > 

的ScrollViewer风格:

<Style TargetType="ScrollViewer" x:Key="myCustomScrollViewerStyle"> 
    ... 
    <ScrollBar x:Name="VerticalScrollBar" Style={StaticResource myCustomScrollBarStyle}" /> 
    <ScrollBar x:Name="HorizontalScrollBar" Style={StaticResource myCustomScrollBarStyle}" /> 
    ... 
</Style> 

滚动条风格:

<Style TargetType="ScrollBar" x:Key="myCustomScrollBarStyle"> 
    ... 
    <Setter Property="Background" Value="Red" /> 
    <Setter Property="Foreground" Value="Green" /> 
    ... 
</Style>