ā Image source not being set with C#, WPF
I have a very basic C# statement but whenever it gets executed the image is not set and the image element disappears.
I have no clue why its not being set, the image is present in that directory, build action of the image is set to content and copy to output is set to copy always
15 Replies
Pack URIs - WPF .NET Framework
Learn about the many ways to use uniform resource identifiers (URIs) to identify and load files in Windows Presentation Foundation (WPF).
Im setting the URI kind to relative and the qrcode.Source returns
pack://application:,,,/Images/scannn.png
man what should i doI cannot reproduce it ... works here as expected
GitHub
GitHub - SirRufo/dc-ImageResourceAndContent
Contribute to SirRufo/dc-ImageResourceAndContent development by creating an account on GitHub.
I have no clue why it isnt working
me too
as you can see it is working in my project
yea
since im creating a qr code its present in Bitmap format so i even converted it into Bitmap Image and tried to set it without any path stil didnt work
the code rn
I did not download your files, but I guess you create the image file from your app and then try to load it with the Uri path?
at first I create the image file and successfully save it and it gets saved i checked and then i set the saved image's location in the image source but that didnt work so then i tried something very straightforward which is setting the image source to an existing image in the Images folder but that didnt work either, so Ik i had the Bitmap so then i converted the Bitmap to BitmapImage and then set it but didnt work and finally rn I tried creating a new Image from code-behind itself and setting its source but didnt work either.
In all of this i got the same result which is that the image is not visible
The key problem is, that if you want to use thoses relative "resources" they have to know at compile time
You can add a dummy png file and set the properties to content and copy always/copy if newer
ive tried that
me too
otherwise you have to use the full path and
UriKind.Absolute
tried that too
ig tried something very similar
using System.IO.Path.Combine() and AppDomain.currentdomain base directory
I also checked using File.Exists() and it was true
.
just found out that setting image source is working perfectly in a different XAML Page
JUST MADE A PROGRESS
there was a logic flaw in my code, when the function to set the image was called just after that there was a line of code that changed the image source
but theres still some problem
NVM I FIXED IT
š„¹
you can close this topic when you post
/close