1

我正在尝试通过 UI 在网格中生成动态控件,其中动态指定控件的大小。在生成超过 1500 个控件时,它会抛出此错误“没有足够的配额可用于处理此命令。(来自 HRESULT 的异常:0x80070718)”。我已经看到了一些针对相同异常的 gridview 解决方案,但我使用的是 GRID,所以对我没有好处。

请告诉我。

提前致谢。

     <ScrollViewer HorizontalScrollMode="Auto" 
              HorizontalScrollBarVisibility="Auto"
              VerticalScrollMode="Auto"
              VerticalScrollBarVisibility="Auto" Margin="232,10,267,0" Grid.Row="1">
                <Grid Name="dynamicgrid" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Background="LightBlue"   Height="Auto" Width="Auto" Grid.Row="1"/>

        </ScrollViewer>
C# code 
 try
            {
                MainPage mainpage = (MainPage)e.Parameter;
                buttons = Convert.ToInt32(mainpage.buttonsize);
                textblock = Convert.ToInt32(mainpage.txtBlocksize);
                textbox = Convert.ToInt32(mainpage.txtBoxsize);
                rows = Convert.ToInt32(mainpage.rows);
                buttonwidth = Convert.ToInt32(mainpage.buttonwidth);
                textblockwidth = Convert.ToInt32(mainpage.txtBlockwidth);
                textboxwidth = Convert.ToInt32(mainpage.txtBoxwidth);
                grdcolumn = buttons + textblock + textbox;


                for (int i = 0; i < rows; i++)
                {
                    RowDefinition rowDef = new RowDefinition();
                    rowDef.Height = new GridLength(200, GridUnitType.Auto);
                    dynamicgrid.RowDefinitions.Add(rowDef);

                }
                for (int j = 0; j < grdcolumn; j++) //need to mention
                {
                    ColumnDefinition colDef1 = new ColumnDefinition();
                    colDef1.Width = new GridLength(100, GridUnitType.Auto);
                    dynamicgrid.ColumnDefinitions.Add(colDef1);
                }

                for (textboxcolumncount = 0; textboxcolumncount < textbox; textboxcolumncount++)
                {
                    for (int i = 0; i < rows; i++)//textbox
                    {
                        TextBox txtbox = new TextBox();
                        txtbox.SetValue(TextBox.TextProperty, "txtbox" + i.ToString());
                        txtbox.Width = textboxwidth;
                        txtbox.Height = 50;
                        txtbox.SetValue(Grid.ColumnProperty, textboxcolumncount);
                        txtbox.SetValue(Grid.RowProperty, i);
                        dynamicgrid.Children.Add(txtbox);
                        dynamicgrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });

                    }
                }
                textboxcolumncount = textbox;
                for (textblockcolumncount = textboxcolumncount; textblockcolumncount < (grdcolumn - (buttons)); textblockcolumncount++)
                {
                    for (int i = 0; i < rows; i++)
                    {
                        TextBlock txtblock = new TextBlock();
                        txtblock.SetValue(TextBlock.NameProperty, "txtblock" + i.ToString());
                        txtblock.Width = textblockwidth;
                        txtblock.Height = 50;
                        txtblock.SetValue(Grid.ColumnProperty, textblockcolumncount);
                        txtblock.SetValue(Grid.RowProperty, i);
                        txtblock.Text = "TextBlock" + i.ToString();
                        txtblock.Foreground = new SolidColorBrush(Colors.Black);
                        dynamicgrid.Children.Add(txtblock);
                        dynamicgrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });

                    }
                }
                textboxcolumncount = textblockcolumncount;
                for (buttonCoulmncount = textboxcolumncount; buttonCoulmncount < (grdcolumn); buttonCoulmncount++)
                {
                    for (int i = 0; i < rows; i++) //button
                    {

                        Button btn = new Button();
                        btn.SetValue(Button.NameProperty, "btn" + i.ToString());
                        btn.Content = "Button" + i.ToString();
                        btn.Width = textboxwidth;
                        btn.Height = 50;
                        btn.Foreground = new SolidColorBrush(Colors.Black);
                        btn.SetValue(Grid.RowProperty, i);
                        btn.SetValue(Grid.ColumnProperty, buttonCoulmncount);
                        dynamicgrid.Children.Add(btn);
                        dynamicgrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });

                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;

            }
4

1 回答 1

0

通过此链接我不确定这是否会解决您的问题,或者您会对此有所了解。

没有足够的配额前

之后,您可以进行搜索。我仍然没有发现任何这样的问题。猜猜必须在系统上复制代码。:)

于 2013-09-06T06:35:32.687 回答