如何将图像插入到网格元素的第二列

时间:2022-02-22 14:17:23

As the subject says I want to insert an image into the 2nd column of grid defined with 2 columndefintions.

就像题目说的,我想把一个图像插入到用2列定义的网格的第二列中。

Programmatically that is???

以编程方式是? ? ?

I cannot see how to select the column using grid.Children.insert(1, img) does not work.

我无法看到如何使用grid.Children选择列。插入(1,img)不起作用。

Malcolm

马尔科姆

2 个解决方案

#1


7  

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

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

包含在网格中的对象是基于附加的依赖属性列列列列列列列列列span和行span进行定位的,如上面所示。

#2


5  

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

WPF中的元素上的行/列索引是一个附加属性。使用网格上的静态方法设置它,如下所示:

Grid.SetColumn(img, 1);

More info here, and more about attached properties here.

更多信息,更多关于附加属性。

#1


7  

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

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

包含在网格中的对象是基于附加的依赖属性列列列列列列列列列span和行span进行定位的,如上面所示。

#2


5  

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

WPF中的元素上的行/列索引是一个附加属性。使用网格上的静态方法设置它,如下所示:

Grid.SetColumn(img, 1);

More info here, and more about attached properties here.

更多信息,更多关于附加属性。