My NET 7 project file looks as follows.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<None Remove="images\RuntimePicture.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\RuntimePicture.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>
</Project>
As the proj file indicates, I have an image in a folder called images.
The code behind ctor looks as follows.
public MainWindow()
{
InitializeComponent();
ImageEx.Source = new BitmapImage(new Uri(@"/images/RuntimePicture.png", UriKind.Relative));
}
The main window xaml for image would be as follows.
<Image x:Name="ImageEx" Height="300" Width="500" />
Finally right click the png file and in the file properties window, ensure Build Action is set to Resource.