嗨我有疑问,如果内容大小小于ListView区域,是否有可能使listview更小,但如果内容更大,请将ListView保留为原样?
目前我有:
<Grid Margin="0,5,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ListView Grid.Row="0" x:Name="Zones" Width="400" Margin="0,0,0,57" MaxHeight="240" Height="Auto" VerticalAlignment="Top">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Top"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Tag="{Binding number}" Background="#FF0E1D23" Margin="0,5,0,0" VerticalAlignment="Top" Height="114" Tapped="Zone_Tapped">
<Grid>
<Grid Visibility="{Binding IsVisible}" Height="115" HorizontalAlignment="Left" Width="13" Background="#FFA4EB1B" VerticalAlignment="Top"/>
<TextBlock TextWrapping="Wrap" Text="{Binding name}" Margin="48,10,10,63" FontSize="24"/>
<Image Margin="48,64,310,18" Source="{Binding modeImg}"/>
<Image Margin="117,64,241,18" Source="{Binding fireImg}"/>
<Image Margin="194,64,164,18" Source="{Binding breakinImg}"/>
<Image Margin="271,64,87,18" Source="{Binding awareImg}"/>
<Image Margin="348,64,10,18" Source="{Binding sabotageImg}"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackPanel Grid.Row="1" x:Name="ZoneMenu1" Background="#FF0E1D23" Margin="0,5,0,0" Height="85" Visibility="Collapsed" VerticalAlignment="Top">
<Grid Height="87">
<Image x:Name="Action1" Margin="10,10,320,0" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Top" Source="ms-appx:///Assets/Images/TopNav/_troubles_48.png" Height="67" Width="70"></Image>
<Image x:Name="Action2" Margin="106,10,225,0" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Top" Source="ms-appx:///Assets/Images/TopNav/_troubles_48.png" Height="67" Width="69"></Image>
<Image x:Name="Action3" Margin="210,10,123,0" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Top" Source="ms-appx:///Assets/Images/TopNav/_troubles_48.png" Height="67" Width="67"></Image>
</Grid>
</StackPanel>
</Grid>
答案 0 :(得分:1)
删除ListView的底部边距57 - 将其设为0。
你的代码中发生的是底部的57个边距强制ListView的底部总是距离屏幕底部57个像素,即使没有足够的内容可以拉伸那么远。
现在因为高度设置为拉伸且对齐为“顶部”,如果在没有设置边距时内容不需要屏幕的整个高度,则ListView将缩小(边距为0,0,0,0意味着没有使用保证金,而不是0像素的边际......这很奇怪,但就是这样。)