代码如下:
<SplitView.Content>
<Grid x:Name="rightFrame" Margin="350,0,0,0" BorderBrush="{ThemeResource ListPickerFlyoutPresenterSelectedItemBackgroundThemeBrush}" BorderThickness="1">
<Grid.Background>
<ImageBrush Stretch="Fill"/>
</Grid.Background>
<Grid Margin="0" Background="{ThemeResource FlipViewButtonBorderThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListView x:Name="InterviewListView" ItemsSource="{x:Bind InterviewModel.TechnicalInterviewRecording }" ShowsScrollingPlaceholders="False" Grid.Row="1" Grid.ColumnSpan="2">
<ListView.Background>
<ImageBrush Stretch="Fill"/>
</ListView.Background>
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:InterviewRecording" >
<Grid>
<Grid Margin="0,0,0,80">
<Grid.Background>
<ImageBrush Stretch="Fill"/>
</Grid.Background>
<Ellipse x:Name="Ellipse" Grid.RowSpan="2" Width ="20" Height="20" Margin="5,0,10,0" VerticalAlignment="Center"
HorizontalAlignment="Left" Fill="LightGray"/>
<TextBlock Text="{x:Bind Question}" FontWeight="Bold" HorizontalAlignment="Left" Margin="30,0,0,0" VerticalAlignment="Center" Width="{Binding InterviewListView.width}"/>
</Grid>
<Grid Margin="0,20,0,30" Padding="0,20,0,0" Height="80">
<TextBlock Text="{x:Bind Anwser}" Margin="35,0,0,0" Width="{Binding InterviewListView.width}"/>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
</Grid>
</SplitView.Content>
数据是从数据库读取的,加载出来的数据不能自适应应用宽度。怎样让listview的item自适应listview的宽度?
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</ListView.ItemContainerStyle>
好像是这2个属性都要设置才行的,还有一个就可以先设listview一个背景色,看下是listview本身有没有适应宽度,没有的话也要给listview设置那2个属性才行。我做win8.1的时候就是这样实现的。
不行唉,这个设置了是居中。我是要每一项item宽度自适应listview的宽度,不然数据不自动换行
@LLLLY: 刚刚写错了属性,是下面这2个属性才对,我一般都是listview设置这2个属性,listviewitem也设置这2个属性,然后就没有问题了
@txy0704: 我都设置了,还是不行