首页新闻找找看学习计划

UWP中怎样让listview的item自适应listview的宽度?

0
悬赏园豆:50 [已解决问题] 解决于 2016-06-13 11:36

代码如下:

<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的宽度?

为你钟情的主页 为你钟情 | 初学一级 | 园豆:39
提问于:2016-06-06 10:26
< >
分享
最佳答案
0

 <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的时候就是这样实现的。

收获园豆:50
txy0704 | 初学一级 |园豆:89 | 2016-06-06 10:35

不行唉,这个设置了是居中。我是要每一项item宽度自适应listview的宽度,不然数据不自动换行

为你钟情 | 园豆:39 (初学一级) | 2016-06-06 10:39

@LLLLY: 刚刚写错了属性,是下面这2个属性才对,我一般都是listview设置这2个属性,listviewitem也设置这2个属性,然后就没有问题了

txy0704 | 园豆:89 (初学一级) | 2016-06-06 11:04

@txy0704: 我都设置了,还是不行

为你钟情 | 园豆:39 (初学一级) | 2016-06-06 11:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册