我正在使用 Xamarin.Forms.DataGrid 数据网格 nuget 包。当我在 Android 手机上运行该应用程序时,它会很好地显示网格和数据。但是,当我尝试在 UWP 上运行完全相同的代码时,它会给我以下异常。
错误信息:
消息“System.Runtime.InteropServices.COMException:已从对 COM 组件的调用返回错误 HRESULT E_FAIL。\r\n 在 Windows.UI.Xaml.UIElement.Measure(Size availableSize)\r\n 在 Xamarin.Forms .Platform.UWP.VisualElementRenderer 2.MeasureOverride
2.MeasureOverride(Size availableSize)\r\n at Windows.UI.Xaml.UIElement.Measure(Size availableSize)\r\n at Xamarin.Forms.Platform.UWP.VisualElementRenderer
(Size availableSize)\r\n at Windows.UI.Xaml.UIElement.Measure(Size availableSize)\r\n at Xamarin.Forms.Plat" 字符串。
如果我注释掉,它将在 UWP 中很好地显示空网格和列
dgReceipts.ItemsSource = tempList;
所以我不相信这可能是 XAML 问题。
用于测试的设备是三星 Galaxy S6 android 7.0 和 Lumia 640
任何帮助表示赞赏
XAML 代码
<dg:DataGrid x:Name="dgReceipts" RowHeight="70" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8">
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="ID" Width="1*">
<dg:DataGridColumn.CellTemplate>
<DataTemplate>
<ContentView>
<Label Text="{Binding Apar_ID}" VerticalOptions="Center"
HorizontalOptions="Center"/>
</ContentView>
</DataTemplate>
</dg:DataGridColumn.CellTemplate>
</dg:DataGridColumn>
</dg:DataGrid.Columns>
<dg:DataGrid.RowsBackgroundColorPalette>
<dg:PaletteCollection>
<Color>#F2F2F2</Color>
<Color>#FFFFFF</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsBackgroundColorPalette>
</dg:DataGrid>
这是我获取数据列表的地方
//Gets transactions for reports page
public async Task<List<x_Transactions>> GetReportTransactions()
{
List<x_Transactions> transactions = await database.Table<x_Transactions>
().ToListAsync();
return transactions;
}
并且它被设置为 dg itemssource
public async Task FillGrid()
{
List<x_Transactions> tempList;
newList = await App.Database.GetReportTransactions();
dgReceipts.ItemsSource = tempList;
}