Here is the C# code snippet for adding BitMap on Flow Document of WPF.
<Grid>
<FlowDocumentPageViewer>
<FlowDocument x:Name="flowDoc" Foreground="White" FontFamily="Arial">
</FlowDocument>
</FlowDocumentPageViewer>
</Grid>
System.Windows.Controls.Image testimage = new System.Windows.Controls.Image();
object o = Properties.Resources.ResourceManager.GetObject("bitmap1");
Bitmap bm = (Bitmap)o;
var memoryStream = new MemoryStream();
bm.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
memoryStream.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memoryStream;
bitmapImage.EndInit();
testimage.Source = bitmapImage;
testimage.Stretch = Stretch.None;
testimage.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
Label lblImageName= new Label();
lblImageName.Content = "bitmap1";
StackPanel sp1 = new StackPanel();
sp1.Children.Add(testimage);
sp1.Children.Add(lblImageName);
dc1.Children.Add(sp1);
BlockUIContainer buc = new BlockUIContainer(dc1);
flowDoc.Blocks.Add(buc);
XAML Code:
<Grid>
<FlowDocumentPageViewer>
<FlowDocument x:Name="flowDoc" Foreground="White" FontFamily="Arial">
</FlowDocument>
</FlowDocumentPageViewer>
</Grid>
Following steps are executed in the above code snippet -- Creating an Image control - testimage
- Retrieve bitmap "bitmap1" from resources
- Reading bitmap in BitmapImage control - "bitmapImage"
- Adding "bitmapImage" in "testimage"
- Creating a label control - "lblImageName"
- Adding "testimage" and "lblImageName" to <stackpanel> sp1
- Adding "sp1" to <Dockpanel> dc1
- Adding "dc1" to BlockUIContainer "buc"
- Adding "buc" to <flowdocument> flowdoc
Comments
Post a Comment