I have bitmap image variable and i want to bind it to my xaml window.
System.Reflection.Assembly thisExe;
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
string[] resources = thisExe.GetManifestResourceNames();
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SplashDemo.Resources.Untitled-100000.png");
Bitmap image = new Bitmap(stream);
And this is my xaml code
<Image Source="{Binding Source}" HorizontalAlignment="Left" Height="210" Margin="35,10,0,0" VerticalAlignment="Top" Width="335">
</Image>
can u assist me binding this bitmap variable to this xaml image by C# code?
If you really want to set it from C# code and not from inside XAML, you should use this easy solution described further on the MSDN reference:
But first, you need to give your
Image
a name so you can reference it from c#:No need to reference Windows Forms classes. If you insist on having the Image embedded into your Assembly, you need the following more lengthy code to load the image:
Here is some sample code:
Click here to view reference
If you are using WPF, right click your image in your project and set the
Build Action
toResource
. Assuming your image is calledMyImage.jpg
and is in aResources
folder in your project, you should be able to reference it directly in yourxaml
without using any C# code. Like this: