WPF, is there any reasonable way to replace a Grid element?

The grid was added by the Row and Column element, I want to add a new element to the grid as follows:

grid.children[i] =element as UieElement;

A mistake occurred to me.

I avoid updating in the stream, so I did not understand Grid.Children.

+3
source share
2 answers

try the following:

grid.Children.RemoveAt(i);
grid.Children.Insert(i, element as UieElement);

(also, but I think this is a typo: children should have capital C in grid.Children ...)

+1
source

To add elements, you will need to do this:

grid.Children.Add(element);

If you want to set a row / column, you can set the properties programmatically before adding it, for example:

element.SetValue(Grid.RowProperty, 1);

You can access the existing part by index, as in your example, if you just need to access a specific child.

0

Source: https://habr.com/ru/post/1780572/


All Articles