Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...