[英]XAML/UWP: Customizing AutoSuggestBox ItemTemplate?
我正在开发一个应用程序,它将使用 API 并带回结果,因此我使用 AutoSuggestBox 来实施建议。 出于设计目的,我需要自定义每个 Suggestion Item,按照它所说的AutoSuggestBox 文档创建自定义 ItemTemplate。
我想让 DataTemplate 的网格填满整个建议空间,但我仍然无法让它工作。
Grid 似乎根据孩子的大小以任意方式设置其宽度,请查看:
编码:
<AutoSuggestBox
Name="inputBox" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="5"
VerticalAlignment="Center" PlaceholderText="Search or paste your video link here."
BorderBrush="#7D1B0A" MinHeight="32"
KeyDown="HandleEnterPress" TextChanged="inputBox_TextChanged" SuggestionChosen="inputBox_SuggestionChosen" ItemsSource="{x:Bind ListItems, Mode=OneWay}">
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<Grid Background="#C92306" BorderBrush="#7D1B0A" BorderThickness="1, 0, 1, 1" HorizontalAlignment="Stretch" VerticalAlignment="Center" MinWidth="150">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding VideoTitle}" Grid.Column="1" Grid.Row="0" FontSize="14" HorizontalAlignment="Left" Foreground="#FFFFFF"/>
<TextBlock Text="{Binding ChannelTitle}" Grid.Column="1" Grid.Row="1" FontSize="12" HorizontalAlignment="Left" Foreground="#FFFFFF"/>
</Grid>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>
这是由于AutoSuggestBox
的建议列表容器,请在AutoSuggestBox
中插入以下代码:
<AutoSuggestBox.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
</Style>
</AutoSuggestBox.ItemContainerStyle>
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.