Xaml 自定义GroupItem标题模板UWP
我正在做一个UWP项目,我不想自定义组项的HeaderTemplate,但我找不到如何完全自定义它Xaml 自定义GroupItem标题模板UWP,xaml,uwp,uwp-xaml,Xaml,Uwp,Uwp Xaml,我正在做一个UWP项目,我不想自定义组项的HeaderTemplate,但我找不到如何完全自定义它 <ListView ItemsSource="{x:Bind ContactsCVS.View}" ItemTemplate="{StaticResource ContactListViewTemplate}" SelectionMode="Single"
<ListView ItemsSource="{x:Bind ContactsCVS.View}"
ItemTemplate="{StaticResource ContactListViewTemplate}"
SelectionMode="Single"
ShowsScrollingPlaceholders="True"
Grid.Row="1"
Grid.ColumnSpan="2">
<ListView.GroupStyle>
<GroupStyle >
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="data:GroupInfoList">
<TextBlock Text="{x:Bind Key}"
Style="{ThemeResource itleTextBlockStyle}"/>
<!-- Can't fully customize this part ?-->
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
我的测试基于以下官方示例:
我试着替换字母A,B,C。。。带有蓝色条纹和自定义文本。看起来很简单,但不知道它是如何工作的
感谢标题模板定义了标题内容的模板,但是显示此内容的实际控件是
列表视图标题项。如果您愿意,您实际上可以简单地执行此操作:
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="data:GroupInfoList">
<Border Background="LightSkyBlue">
<TextBlock Text="My custom text" />
</Border>
</DataTemplate>
</GroupStyle.HeaderTemplate>
ContentPresenter
负责显示控件的内容
,在这种情况下,内容就是标题模板中的内容
非常感谢!我现在明白了:)
<GroupStyle.HeaderContainerStyle>
<Style TargetType="ListViewHeaderItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewHeaderItem">
<ContentPresenter
x:Name="ContentPresenter"
Background="Red"
Margin="0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="Stretch"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTransitions="{TemplateBinding ContentTransitions}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.HeaderContainerStyle>