After much research I am stuck as I’m not able to make an image appear dynamically.
It is pretty much the same problem as this: Dynamic loading of images in WPF
Here is my actual code at the moment
Dim logo As New Image
Dim logoSource As New BitmapImage
logoSource.BeginInit()
logoSource.UriSource = New Uri("../../Images/CarpeDiemLogo.gif", UriKind.Relative)
logoSource.CacheOption = BitmapCacheOption.OnLoad
logoSource.EndInit()
logo.Height = 109
logo.Width = 172
logo.HorizontalAlignment = Windows.HorizontalAlignment.Right
logo.VerticalAlignment = Windows.VerticalAlignment.Top
logo.Source = logoSource
logo.Stretch = Stretch.Uniform
g.Children.Add(logo)'Where g is a grid
As you can see it is quite similar yet I run into a problem.
I am trying to add the image to a user control used as an header template for printing using this print engine: http://www.codeproject.com/Articles/238135/WPF-Print-Engine-Part-I
At some point in the print engine it passes this code of line
var header = XamlReader.Parse(PrintTableDefination.HeaderTemplate) as FrameworkElement;
If logoSource.CacheOption = BitmapCacheOption.OnLoad is not commented it tells me “‘The initialization of ‘System.Windows.Media.Imaging.BitmapImage’ raised an exception’ line and line position 826.”
However if that line is comented it goes through but th eimage is not displayed.
Is there something I’m doing wrong? Limitations of the Xaml reader? I’ve searched and tried with different methods for creating the image dynamically and yet none of them loaded it.
Any suggestions will be considered and tried. I’m desperate at the moment…
Thanks
I ended up modifying the source code of the print engine and passing to the function that prints the header a title where I’d replace “@title” found in the content of a label I’d put inside the header template.
Sadly this doesn’t answer the initial question but yet it is a workaround for me.