【发布时间】:2017-10-18 03:25:46
【问题描述】:
我遇到了一个奇怪的问题。这仅在 Xamarin 形式 - UWP 中发生。我在 Listview 中使用 Listview。当我单击每个列表时,将显示子列表。我还为子列表设置了一个固定的高度,以便可以滚动它。现在在检查时,即使它有更多的项目,底部也填充了黑色。我该如何解决这个问题。
用于列表的 XAML:
<ListView x:Name="MyProducts"
IsRefreshing="{Binding IsBusy, Mode=TwoWay}"
RefreshCommand="{Binding GetAllProducts,Mode=TwoWay}"
IsPullToRefreshEnabled="true"
HasUnevenRows="True"
BackgroundColor="White"
ItemSelected="CategorySelected"
SeparatorVisibility="None"
ItemsSource="{Binding MyProductsList}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#e6e6e6" Margin="0,2,0,2">
<StackLayout Margin="1" BackgroundColor="White">
<Grid Padding="0,10,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="Product Category" YAlign="Center" Margin="10,0,0,0" Style="{DynamicResource LabelLightStyle}"/>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding Model.ProductCategoryName}" Style="{DynamicResource LabelRedStyle}" YAlign="Center" Margin="10,0,0,0"/>
<Image Grid.Row="0" Grid.Column="1" IsVisible="{Binding IconDown}" Source="ArrowDown.png" HeightRequest="15" Grid.RowSpan="2" Margin="0,0,5,0" HorizontalOptions="End" VerticalOptions="Center"/>
<Image Grid.Row="0" Grid.Column="1" IsVisible="{Binding IconUp}" Source="ArrowUp.png" HeightRequest="15" Grid.RowSpan="2" Margin="0,0,5,0" HorizontalOptions="End" VerticalOptions="Center"/>
<ListView Grid.Row="2" Grid.ColumnSpan="2"
IsVisible="{Binding ListVisibility}"
SeparatorVisibility="Default"
SeparatorColor="#e6e6e6"
ItemSelected="ProductSelected"
HeightRequest="220"
BackgroundColor="#f2f2f2"
HorizontalOptions="FillAndExpand"
ItemsSource="{Binding Model.Products}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#e6e6e6">
<StackLayout Margin="0,0,0,1" BackgroundColor="#f2f2f2">
<Grid Padding="0,10,0,10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding MachineModel, StringFormat='Machine Model Number : {0}'}" YAlign="Center" Margin="10,0,0,0" Style="{DynamicResource LabelStyle}"/>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding CreatedDate, StringFormat='Date {0}'}" Style="{DynamicResource LabelTinyStyle}" YAlign="Center" Margin="10,0,0,0"/>
<Image Grid.Row="0" Grid.Column="1" Source="ArrowRight.png" HeightRequest="15" Grid.RowSpan="2" Margin="0,0,10,0" HorizontalOptions="End" VerticalOptions="Center"/>
</Grid>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
【问题讨论】:
-
您的 XAML 在哪里?可以发一下吗?
-
这在 IOS 和 android 中运行良好。这个奇怪的问题只在 UWP 中发生。请找到使用的xaml docs.google.com/document/d/…
-
为什么
DataTemplate中有2个StackLayout,一个是BackgroundColor="#e6e6e6",另一个是BackgroundColor="White"? -
@avk-naidu 用于显示边框。我必须做一些调整才能在 UWP 中获得更好的视图。但这不是问题。仅当我尝试为 Listview 提供高度时才会出现问题。我已经给出了它,因为我的列表很长,我只需要在列表的有限高度内下拉的滚动效果
标签: uwp xamarin.forms uwp-xaml