We can do something like this:
--- Source code ------
#events Create WPF Image Control
using System.Windows.Controls;
using System.Diagnostics;
using System.IO;
// add WPF image control
AddImageControl(this);
#endevents
#panelmethods Create WPF Image Control
// Add image control to the Plex Panel
void AddImageControl(App.UI.Image.AA4zF_ObPnl panel) {
System.Windows.Controls.Image wb = new System.Windows.Controls.Image();
// return a reference to the obj for further actions
&(1:).Value = wb;
// set some properties
wb.Width = 300;
wb.Height = 300;
wb.Margin = new Thickness(100, 100, 0, 0);
wb.HorizontalAlignment = HorizontalAlignment.Left;
wb.VerticalAlignment = VerticalAlignment.Top;
// load a byte array (simulation of the one you get from LDAP)
try
{
FileStream fs = null;
fs = File.OpenRead("C:\\myImage.jpg");
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
if (fs != null)
{
fs.Close();
fs.Dispose();
}
// Bitmap
BitmapImage bmpi = new BitmapImage();
bmpi.BeginInit();
bmpi.StreamSource = new MemoryStream(bytes);
bmpi.EndInit();
// set the source to the control
wb.Source = bmpi;
}
catch (Exception ex) { System.Diagnostics.Debug.Write(ex.StackTrace); }
// add to ObUIGrid
ObScrollViewer obscroll = (ObScrollViewer)panel.Content;
ObUIGrid obuigrid = (ObUIGrid)obscroll.Content;
obuigrid.Children.Add(wb);
Debug.WriteLine(panel.Content);
}
#endpanelmethods
---end source code --