Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
964 views
in Technique[技术] by (71.8m points)

xamarin.forms - How to assign the grid to a grid

I new a grid object without any settings in the xaml file. After importing the data through 'Build_Grid()' in the 'OnAppearing()', I want to assign the 'gridview' to 'Grid_Info' to display on the screen, the code 'Grid_Info = gridview' does not work. I am wondering how to achieve my needs?

<ContentPage.Content>
<StackLayout>
<Label Text="AAA" />
<Grid x:Name="Grid_Info">
</Grid>
</StackLayout>
</ContentPage.Content>


    void Build_Grid(Data data)
        {
        Grid gridview = new Grid();
        gridview.RowDefinitions.Add(new RowDefinition() { Height = 40 });
        gridview.Children.Add(data[0],0,0);
        ...
Grid_Info = gridview; //it does not work...
        }

protected override void OnAppearing()
{
Data data = new Data();
...
Build_Grid(data);
}
question from:https://stackoverflow.com/questions/65860994/how-to-assign-the-grid-to-a-grid

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

if you've already defined the Grid in XAML there is no need to do this

Grid gridview = new Grid();

instead just reference Grid_Info directly

Grid_Info.RowDefinitions.Add(new RowDefinition() { Height = 40 });
Grid_Info.Children.Add(data[0],0,0);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...