tags:

views:

1630

answers:

2

Hi,

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

Programmatically that is???

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

Malcolm

+4  A: 

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

Grid.SetColumn(img, 1);

More info here, and more about attached properties here.

Matt Hamilton
+5  A: 
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.

sflanker
Shouldn't you first add the Image to the Grid and then set the column?
Boyan
Either way is fine since Column is an AttachedProperty on Grid. You can set that before adding to grid.
Jobi Joy