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