我试图在添加另一个值时扩展 Datagrid。使用 Xamarin.Forms.Datagrid

I'm trying to expand the Datagrid when adding another value. Using Xamarin.Forms.Datagrid

我正在使用 Xamarin.Forms.Datagrid。我正在努力的是显示第二行。我怀疑是在我没有指定向 Datagrid 添加新行的附加值部分。但是我这辈子都看不到了。

现在如果我扫描不同的条形码。它将新值添加到集合中但不扩展数据网格。

我的 ObservableCollection:

public ObservableCollection<dgvProductionReceiptSource> ProductionReceiptSource { get; } = new ObservableCollection<dgvProductionReceiptSource>();

我从哪里获取数据:

private void FillDataGrid()
    {
        try
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand("SELECT DocNum, OWOR.ItemCode, ItemName, PlannedQty, CAST(OWOR.DueDate AS DATE) FROM OWOR " +
                    "INNER JOIN OITM ON OWOR.ItemCode = OITM.ItemCode WHERE Status = 'R' AND OWOR.DocNum = '" + ScanBarcodeText + "' ORDER BY DueDate ASC", connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {

                        if (reader != null)
                        {
                            while (reader.Read())
                            {
                                
                                ItemNum = reader.GetString(1);
                                Desc = reader.GetString(2);
                                PlannedQty = reader.GetDecimal(3);
                                DueDate = reader.GetDateTime(4);
                                ScanQty = 0;

                                if (DueDate == DateTime.Today)
                                {
                                    if (DocNum.ToString() == ScanBarcodeText)
                                    {
                                        AddQty();
                                    }
                                    
                                    if (DocNum.ToString() != ScanBarcodeText)
                                    {
                                        DocNum = reader.GetInt32(0);
                                        ProductionReceiptSource.Add(new dgvProductionReceiptSource()
                                        {
                                            DocNumProductionReceipt = DocNum,
                                            ItemNumberProductionReceipt = reader.GetString(1),
                                            DescriptionProductionReceipt = reader.GetString(2),
                                            PlannedQuantityProductionReceipt = reader.GetDecimal(3),
                                            ScannedQuantityProductionReceipt = 0
                                        });
                                        AddQty();
                                    }
                                }
                            }
                        }
                    }
                }
                connection.Close();
            }
            ScanBarcodeText = string.Empty;
        }
        catch(Exception ex)
        {
            Application.Current.MainPage.DisplayAlert("Alert", ex.Message, "OK");
        }
    }

如有任何帮助,我们将不胜感激

按照Jason的建议,我需要增加控件的高度

            <ContentView HeightRequest="380">
                <ScrollView Orientation="Horizontal">
                    <dg:DataGrid x:Name="dgvProductionReceiptSource" 
                                 ItemsSource="{Binding ProductionReceiptSource}"
                                 IsRefreshing="{Binding ProductionReceiptRefresh}"
                                 PullToRefreshCommand="{Binding ProductionReceiptRefreshCommand}"
                                 IsVisible="False"
                                 RowHeight="60" 
                                 HeaderHeight="50"
                                 HeaderBackground="#e0e6f8"
                                 HeaderFontSize="15"
                                 ActiveRowColor="#8899AA">
                        <x:Arguments>
                            <ListViewCachingStrategy>RetainElement</ListViewCachingStrategy>
                        </x:Arguments>
                        <dg:DataGrid.Columns>
                            <dg:DataGridColumn Title="Order Number" PropertyName="DocNumProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Item Number" PropertyName="ItemNumberProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Item Description" PropertyName="DescriptionProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Planned Quantity" PropertyName="PlannedQuantityProductionReceipt" Width="150"
                                           HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Scanned Bin" PropertyName="ScannedBinsProductionReceipt" Width="150"
                                               HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                            <dg:DataGridColumn Title="Remaining Bins" PropertyName="RemainingBinsProductionReceipt" Width="150"
                                               HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                        </dg:DataGrid.Columns>
                        <dg:DataGrid.RowsBackgroundColorPalette>
                            <dg:PaletteCollection>
                                <Color>#E0E6f8</Color>
                            </dg:PaletteCollection>
                        </dg:DataGrid.RowsBackgroundColorPalette>
                    </dg:DataGrid>
                </ScrollView>
            </ContentView>

我更改了 ContentView 高度请求