我想水平拉伸ListView
在UWP 10中。我还设置了HorizontalContentAlignment
to Stretch
。它有点有效,但并不完全是我想要的结果。
我将 ListView 背景设置为 Aqua,因此您可以看到 ListView 本身拉伸到 100%。
内容也在拉伸,但我在左侧和右侧都有这个空间。
所以我的问题是:如何删除左右的“边距”?
结果如下:
这是 XAML:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<AutoSuggestBox x:Name="SalonSearchBox"
Grid.Row="0"
QueryIcon="Find"
PlaceholderText="Suchen..."
Margin="8" />
<ListView x:Name="SalonsListView"
Grid.Row="1"
Background="Aqua"
ItemsSource="{x:Bind ViewModel.Salons, Mode=OneWay}"
HorizontalAlignment="Stretch"
Margin="0">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate x:DataType="salon:Salon">
<Grid Height="110"
Padding="8">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="{x:Bind ListingImage}"
Stretch="UniformToFill" />
</Grid.Background>
<TextBlock x:Name="TitleTextBlock"
Grid.Row="1"
Text="{x:Bind Name}"
FontSize="20"
Foreground="White"
FontWeight="SemiBold" />
<TextBlock x:Name="LocationTextBlock"
Grid.Row="2"
Foreground="White"
FontWeight="SemiLight">
<Run Text="{x:Bind Place.PLZ}" />
<Run Text="{x:Bind Place.Address}" />
</TextBlock>
<TextBlock x:Name="DescriptionTextBlock"
FontWeight="SemiLight"
Grid.Row="3"
x:Phase="1"
Text="{x:Bind Info}"
Foreground="Gray" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Grid>
你需要修改项目容器样式填充和边距:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"/>
</Style>
</ListView.ItemContainerStyle>
您还定义了Grid's填充到 8,将导致项目周围出现水绿色背景。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)