最近我在自己的Xamarin项目中使用了Xamarin.Forms.DataGrid。
当我在StackLayout中插入多个组件时,我发现datagrid只显示标题之外的数据。
有人知道我做错了什么吗?
XAML代码发布在以下位置:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
x:Class="Spray.Views.QC2">
<ContentView>
<StackLayout>
<Entry x:Name="entryName" Placeholder="Name" Text="lai"/>
<dg:DataGrid x:Name="dataGridView1" ItemsSource="{Binding Jobs}" SelectionEnabled="True" RowHeight="70" HeaderHeight="50"
BorderColor="#CCCCCC" HeaderBackground="#E0E6F8" PullToRefreshCommand="{Binding RefreshCommand}"
IsRefreshing="{Binding IsRefreshing}" ActiveRowColor="#8899AA" ItemSelected = "onItemSelected">
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="PN" PropertyName="pn" Width="2*"/>
<dg:DataGridColumn Title="Quantity" PropertyName="quantity" Width="1*"/>
<dg:DataGridColumn Title="Worker" PropertyName="worker" Width="1*"/>
<dg:DataGridColumn Title="QC Sign" PropertyName="signature" Width="1*"/>
<dg:DataGridColumn Title="Time" PropertyName="time" Width="1*"/>
</dg:DataGrid.Columns>
<dg:DataGrid.RowsBackgroundColorPalette>
<dg:PaletteCollection>
<Color>#F2F2F2</Color>
<Color>#FFFFFF</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsBackgroundColorPalette>
</dg:DataGrid>
</StackLayout>
</ContentView>
</ContentPage>
谢谢你的帮助!
特里·比尔
此外,我已经尝试了Jason的建议,添加高度值和VerticalOption值如下,但结果仍然是一样的。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
x:Class="Spray.Views.QC2">
<ContentView>
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" HeightRequest="300">
<Entry x:Name="entryName" Placeholder="Name" Text="lai"/>
<dg:DataGrid x:Name="dataGridView1" ItemsSource="{Binding Jobs}" SelectionEnabled="True" RowHeight="70" HeaderHeight="50"
BorderColor="#CCCCCC" HeaderBackground="#E0E6F8" PullToRefreshCommand="{Binding RefreshCommand}"
IsRefreshing="{Binding IsRefreshing}" ActiveRowColor="#8899AA" ItemSelected = "onItemSelected">
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="PN" PropertyName="pn" Width="2*"/>
<dg:DataGridColumn Title="Quantity" PropertyName="quantity" Width="1*"/>
<dg:DataGridColumn Title="Worker" PropertyName="worker" Width="1*"/>
<dg:DataGridColumn Title="QC Sign" PropertyName="signature" Width="1*"/>
<dg:DataGridColumn Title="Time" PropertyName="time" Width="1*"/>
</dg:DataGrid.Columns>
<dg:DataGrid.RowsBackgroundColorPalette>
<dg:PaletteCollection>
<Color>#F2F2F2</Color>
<Color>#FFFFFF</Color>
</dg:PaletteCollection>
</dg:DataGrid.RowsBackgroundColorPalette>
</dg:DataGrid>
</StackLayout>
</ContentView>
</ContentPage>
1条答案
按热度按时间piah890a1#
您可以尝试在
ContentPage
中添加一个StackLayout
,并将组件和DataGrid
作为它的子组件。您还需要为您的
ContentView
设置HeightRequest
。请参考以下代码: