WPF - how to insert an image into the second column of a Grid element

As the subject says, I want to insert an image in the second column of the grid with two column arguments.

Programmatically what is

I can't see how to select a column using grid.Children.insert (1, img) doesn't work.

Malcolm

+1


source to share


2 answers


Image imgControl = new Image();
Grid.SetColumn(imgControl, 1);
gridContainer.Children.Add(imgControl);

      



The objects contained in the grid are positioned based on the attached Column Row ColumnSpan and RowSpan dependency properties, which are set as shown above.

+7


source


The row / column index on an element in WPF is an attached property. You set it using a static method on the Grid, for example:

Grid.SetColumn(img, 1);

      



More information here , and a lot more about attached properties here .

+5


source







All Articles