![](/img/trans.png)
[英]xaml block horizontal and vertical window size adjustment, diagonal change only
[英]XAML change size and display of horizontal scroll bar
我正在嘗試更改水平滾動條的大小和顯示。 目前,僅當我移動listview項時才會顯示滾動條。 我需要把它變大並為它添加顏色。 我可以使用它的風格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>
您可以為ListView及其內部ScrollViewer和ScrollBar創建自定義樣式。
您將在此處找到要覆蓋的樣式的定義:
如果要更改應用程序的所有ScrollBars,則覆蓋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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.