1

Why does it not work?

I also did these variant ./icon/icon.png, pack://application:,,,/icon/icon.png, pack://MyProject:,,,/icon/icon.png or fetched the icon from the directory and tried these variant /icon.png, pack://application:,,,/icon.png, pack://MyProject:,,,/icon.png but that doesn`t work either.

I got this error message: IOException: Cannot locate resource 'icon/icon.png'.

How should I write the path?

<Window x:Class="MyProject.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MyProject"
        mc:Ignorable="d"
        Title="MyProject" Height="450" Width="800" Icon="icon/icon.png">
    <Canvas>
    </Canvas>
</Window>
  • 2
    Make sure that the file `icon.png` is located in a folder named `icon` in your Visual Studio project and that its `Build Action` is set to `Resource`. – Clemens Nov 16 '22 at 21:43

0 Answers0