gpt4 book ai didi

xaml - 在 UWP 中保持 ListView.HeaderTemplate 可见/静态/粘性

转载 作者:行者123 更新时间:2023-12-04 13:58:22 27 4
gpt4 key购买 nike

我需要保留 HeaderTemplateListView始终可见,但我不知道该设置什么,或者 ListView 的哪个部分的模板来改变来做到这一点。

我目前拥有的导致 ListView 的标题向下滚动项目时从顶部滚动。

如何保留 ListView 的标题“行”即使滚动浏览 ListView 也可见的元素??

这是我的 XAML:

<ListView x:Name="permitResults"
Grid.Row="1"
AutomationProperties.AutomationId="PermitResults"
AutomationProperties.Name="Permit Search Results"
ItemsSource="{Binding Source={StaticResource ResultsSource}}"
ItemClick="permitResults_ItemClick"
SelectionMode="None"
TabIndex="1"
Padding="0"
Margin="0"
BorderThickness="0"
IsSwipeEnabled="True"
IsItemClickEnabled="True"
ScrollViewer.VerticalScrollBarVisibility="Auto" >
<ListView.HeaderTemplate>
<DataTemplate>
<Grid Margin="0,0,0,0" Width="1366" Height="Auto" HorizontalAlignment="Left">
<Grid.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource SearchGridResultsHeaderTextBlock}">
<Setter Property="HorizontalAlignment" Value="Left"></Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Permit #" MaxLines="2" TextWrapping="WrapWholeWords"/>
<TextBlock Grid.Column="1" Text="County" TextWrapping="WrapWholeWords" />
<TextBlock Grid.Column="2" Text="Business Name" TextWrapping="WrapWholeWords" />
<TextBlock Grid.Column="3" Text="Status" TextWrapping="WrapWholeWords" />
<TextBlock Grid.Column="4" Text="Type" TextWrapping="WrapWholeWords" />
<TextBlock Grid.Column="5" Text="FY" TextWrapping="WrapWholeWords" />
</Grid>
</DataTemplate>
</ListView.HeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="-11,0,0,0" Width="1366" Height="Auto">
<Grid.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource SearchGridResultsTextBlock}">
<Setter Property="HorizontalAlignment" Value="Left"></Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="44"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding PermitNumber}" TextWrapping="WrapWholeWords" />
<TextBlock Grid.Column="1" Text="{Binding County}" TextWrapping="NoWrap" />
<TextBlock Grid.Column="2" Text="{Binding BusinessName}" TextWrapping="NoWrap" />
<TextBlock Grid.Column="3" Text="{Binding Status}" TextWrapping="NoWrap" />
<TextBlock Grid.Column="4" Text="{Binding PermitType}" TextWrapping="NoWrap" />
<TextBlock Grid.Column="5" Text="{Binding EffFiscalYear}" TextWrapping="NoWrap" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

最佳答案

将此样式应用于您的 ListView你将有静态标题

    <Style TargetType="ListView" x:Key="FixedHeaderListViewStyle">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TabNavigation" Value="Once" />
<Setter Property="IsSwipeEnabled" Value="True" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Enabled" />
<Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="True" />
<Setter Property="ScrollViewer.ZoomMode" Value="Disabled" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
<Setter Property="ScrollViewer.BringIntoViewOnFocusChange" Value="True" />
<Setter Property="UseSystemFocusVisuals" Value="True" />
<Setter Property="ItemContainerTransitions">
<Setter.Value>
<TransitionCollection>
<AddDeleteThemeTransition />
<ContentThemeTransition />
<ReorderThemeTransition />
<EntranceThemeTransition IsStaggeringEnabled="False" />
</TransitionCollection>
</Setter.Value>
</Setter>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListView">
<Border BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>

<ContentControl Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
ContentTransitions="{TemplateBinding HeaderTransitions}"/>

<ScrollViewer x:Name="ScrollViewer"
Grid.Row="1"
TabNavigation="{TemplateBinding TabNavigation}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
IsHorizontalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsHorizontalScrollChainingEnabled}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
IsVerticalScrollChainingEnabled="{TemplateBinding ScrollViewer.IsVerticalScrollChainingEnabled}"
IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
ZoomMode="{TemplateBinding ScrollViewer.ZoomMode}"
IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
BringIntoViewOnFocusChange="{TemplateBinding ScrollViewer.BringIntoViewOnFocusChange}"
AutomationProperties.AccessibilityView="Raw">
<ItemsPresenter
Footer="{TemplateBinding Footer}"
FooterTemplate="{TemplateBinding FooterTemplate}"
FooterTransitions="{TemplateBinding FooterTransitions}"
Padding="{TemplateBinding Padding}" />
</ScrollViewer>

</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

关于xaml - 在 UWP 中保持 ListView.HeaderTemplate 可见/静态/粘性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38513410/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com