I'm newbie in .NET (WPF) and I'm stucked in somethin I guess it's really trivial.

I'm creating a FlowDocument and a Table from C# code. enter image description here

When I'm about to create the rows, I need to insert a image inside the cells "Prediction"

// ******* TODAY ROW ******
oTable.RowGroups[0].Rows.Add(new TableRow());
currentRow = oTable.RowGroups[0].Rows[1];

//Configure the row layout
currentRow.Background = System.Windows.Media.Brushes.White;
currentRow.Foreground = System.Windows.Media.Brushes.Navy;

//Add the dayin the first cell
currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Today"))));

//Add the image in the second cell
BitmapImage bmp0 = new BitmapImage();
System.Windows.Controls.Image img0 = new System.Windows.Controls.Image();
bmp0.BeginInit();
bmp0.UriSource = new Uri("weather/cloudy.gif", UriKind.Relative);
bmp0.EndInit();
Paragraph oParagraph0 = new Paragraph();
oParagraph0.Background = new ImageBrush(bmp0);
currentRow.Cells.Add(new TableCell(oParagraph0));

As you can see, now I'm setting the image "bmp0" just as background of the paragraph... How can I set it as a normal Image (without resizing it as the background)?

有帮助吗?

解决方案

You may put the Image control img0 in a BlockUIContainer (or InlineUIContainer as well):

var bitmap = new BitmapImage(new Uri("weather/cloudy.gif", UriKind.Relative));
var image = new Image { Source = bitmap };
var block = new BlockUIContainer(image);

currentRow.Cells.Add(new TableCell(block));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top