简体   繁体   English

XAML更改大小并显示水平滚动条

[英]XAML change size and display of horizontal scroll bar

I am trying to change the size and display of the horizontal scroll bar. 我正在尝试更改水平滚动条的大小和显示。 Currently the scroll bar is displayed only when I move the listview items. 目前,仅当我移动listview项时才会显示滚动条。 I need to make it bigger and add color to it. 我需要把它变大并为它添加颜色。 Can I use style for it plz. 我可以使用它的风格PLZ。

 <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>

You can create a custom style for your ListView and its internal ScrollViewer and ScrollBar. 您可以为ListView及其内部ScrollViewer和ScrollBar创建自定义样式。

You will find the definitions for the styles to override here: 您将在此处找到要覆盖的样式的定义:

If you want to change all the ScrollBars of your app, overriding ScrollBar style will be enough 如果要更改应用程序的所有ScrollBars,则覆盖ScrollBar样式就足够了

If you want this custom style to apply only within your ListView, it will be more tricky. 如果您希望此自定义样式仅应用于ListView,则会更加棘手。

You will have to create a custom ScrollBar style changing the properties you want. 您必须创建自定义ScrollBar样式,以更改所需的属性。 Then create a custom ScrollViewer style which will reference/use your custom ScrollBar style. 然后创建一个自定义ScrollViewer样式,它将引用/使用您的自定义ScrollBar样式。 And finally, create a custom ListView style which will reference/use your custom ScrollViewer style. 最后,创建一个自定义ListView样式,它将引用/使用您的自定义ScrollViewer样式。

It will look as the following: 它将如下所示:

ListView style: 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: Scrollviewer风格:

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

Scrollbar style: 滚动条样式:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM