C
C#11mo 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
ero11mo ago
you want to include them as resources that should work in wpf
Ossie
Ossie11mo ago
How do I do that?
ero
ero11mo ago
exchange Content with Resource
Ossie
Ossie11mo ago
Okay, I'll give it a go, thanks
ero
ero11mo ago
or do it in the designer of course or not designer, the file properties window
Ossie
Ossie11mo ago
<ItemGroup>
<Resource Include="Images/*.*"/>
</ItemGroup>
<ItemGroup>
<Resource Include="Images/*.*"/>
</ItemGroup>
Like this?
ero
ero11mo ago
i would think so?
Ossie
Ossie11mo ago
No, doesn't work still...
Ossie
Ossie11mo ago
ero
ero11mo ago
how are you trying to access this?
Ossie
Ossie11mo ago
Ossie
Ossie11mo ago
Ossie
Ossie11mo ago
Like this, from xaml
ero
ero11mo ago
oh, actually content was correct lol articles online say you need to CopyIfNewer
Ossie
Ossie11mo ago
So not resource?
ero
ero11mo ago
but this makes me wonder whether it will work without having to ship the images along the binaries
Kouhai
Kouhai11mo ago
<Resource Include=".."> should work
Ossie
Ossie11mo 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
ero11mo ago
.
Ossie
Ossie11mo ago
Where do I use that?
Kouhai
Kouhai11mo ago
You don't need CopyIfNewer with Resource
Ossie
Ossie11mo ago
But it doesn't work with Resource Include I get this
Kouhai
Kouhai11mo ago
Hmmm, that's odd I have a wpf project open and it works
Ossie
Ossie11mo ago
How do you point to it From XAML
ero
ero11mo ago
where is your images folder? relative to the csproj file?
Ossie
Ossie11mo ago
The same
ero
ero11mo ago
what?
Ossie
Ossie11mo ago
Kouhai
Kouhai11mo 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
Ossie11mo ago
It also shows them in the XAML editor, its only when I run it
ero
ero11mo ago
well they're not using an Image might be that
Ossie
Ossie11mo 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
ero11mo ago
why would you do it like that then lmao why not add an image over the full row and columnspan
Ossie
Ossie11mo ago
How would you do it then?
ero
ero11mo ago
<Grid>
<Image RowSpan="" ColumnSpan="" Source="Images/Background.png" />
</Grid>
<Grid>
<Image RowSpan="" ColumnSpan="" Source="Images/Background.png" />
</Grid>
Ossie
Ossie11mo ago
I cannot leave them empty
ero
ero11mo ago
so add the numbers you need...
Ossie
Ossie11mo ago
Idk which numbers I need I just want the background of the whole page to be the image
ero
ero11mo ago
however many rows and columns the grid has
Ossie
Ossie11mo ago
None
ero
ero11mo ago
so the image spans over the entire grid so put 0 or remove them and come on
MODiX
MODiX11mo 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
Ossie11mo ago
I haven't used grids with that before lol, I also tagged it as beginner
Kouhai
Kouhai11mo 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
Accord11mo 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.