C
C#2y ago
Ossie

❔ Embed images within .exe [WPF App .Net 6.0]

Hey, I have some Images that I would like to use within my app, how do I have them embedded within the .exe, I tried to do
<Content Include="Images/*.*"/>
<Content Include="Images/*.*"/>
But, then it tries to get the images from the build output/images/theimage.png How do I have them within the .exe, I was able to do this in older version of WPF Thanks
45 Replies
ero
ero2y ago
you want to include them as resources that should work in wpf
Ossie
OssieOP2y ago
How do I do that?
ero
ero2y ago
exchange Content with Resource
Ossie
OssieOP2y ago
Okay, I'll give it a go, thanks
ero
ero2y ago
or do it in the designer of course or not designer, the file properties window
Ossie
OssieOP2y ago
<ItemGroup>
<Resource Include="Images/*.*"/>
</ItemGroup>
<ItemGroup>
<Resource Include="Images/*.*"/>
</ItemGroup>
Like this?
ero
ero2y ago
i would think so?
Ossie
OssieOP2y ago
No, doesn't work still...
Ossie
OssieOP2y ago
ero
ero2y ago
how are you trying to access this?
Ossie
OssieOP2y ago
Ossie
OssieOP2y ago
Ossie
OssieOP2y ago
Like this, from xaml
ero
ero2y ago
oh, actually content was correct lol articles online say you need to CopyIfNewer
Ossie
OssieOP2y ago
So not resource?
ero
ero2y ago
but this makes me wonder whether it will work without having to ship the images along the binaries
Kouhai
Kouhai2y ago
<Resource Include=".."> should work
Ossie
OssieOP2y ago
With Content instead of Resource, it still doesn't work If I do the content one, it tries to find it from the build output folder
ero
ero2y ago
.
Ossie
OssieOP2y ago
Where do I use that?
Kouhai
Kouhai2y ago
You don't need CopyIfNewer with Resource
Ossie
OssieOP2y ago
But it doesn't work with Resource Include I get this
Kouhai
Kouhai2y ago
Hmmm, that's odd I have a wpf project open and it works
Ossie
OssieOP2y ago
How do you point to it From XAML
ero
ero2y ago
where is your images folder? relative to the csproj file?
Ossie
OssieOP2y ago
The same
ero
ero2y ago
what?
Ossie
OssieOP2y ago
Kouhai
Kouhai2y ago
In csproj <Resource Include="Resources\doc.png"> In XAML
<Image Width="16"
Height="16"
Source="Resources\doc.png" />
<Label Content="New" />
<Image Width="16"
Height="16"
Source="Resources\doc.png" />
<Label Content="New" />
Ossie
OssieOP2y ago
It also shows them in the XAML editor, its only when I run it
ero
ero2y ago
well they're not using an Image might be that
Ossie
OssieOP2y ago
In csjproj: `<Resource Include="Images/Background.png" />`` XAML
<ImageBrush ImageSource="Images/Background.png"/>
<ImageBrush ImageSource="Images/Background.png"/>
Grid.Background can only accept ImageBrush
ero
ero2y ago
why would you do it like that then lmao why not add an image over the full row and columnspan
Ossie
OssieOP2y ago
How would you do it then?
ero
ero2y ago
<Grid>
<Image RowSpan="" ColumnSpan="" Source="Images/Background.png" />
</Grid>
<Grid>
<Image RowSpan="" ColumnSpan="" Source="Images/Background.png" />
</Grid>
Ossie
OssieOP2y ago
I cannot leave them empty
ero
ero2y ago
so add the numbers you need...
Ossie
OssieOP2y ago
Idk which numbers I need I just want the background of the whole page to be the image
ero
ero2y ago
however many rows and columns the grid has
Ossie
OssieOP2y ago
None
ero
ero2y ago
so the image spans over the entire grid so put 0 or remove them and come on
MODiX
MODiX2y ago
AttachedProperty: System.Windows.Controls.Grid.RowSpan Gets or sets a value that indicates the total number of rows that child content spans within a Grid. Field: System.Windows.Controls.Grid.RowSpanProperty Identifies the RowSpan attached property.
React with ❌ to remove this embed.
Ossie
OssieOP2y ago
I haven't used grids with that before lol, I also tagged it as beginner
Kouhai
Kouhai2y ago
If you still want to use ImageBrush
<Grid>
<Grid.Background>
<ImageBrush ImageSource="Images/Background.png" />
</Grid.Background>
</Grid>
<Grid>
<Grid.Background>
<ImageBrush ImageSource="Images/Background.png" />
</Grid.Background>
</Grid>
<ItemGroup>
<Resource Include="Images\Background.png"></Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Background.png"></Resource>
</ItemGroup>
Should work
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?