Search code examples
xamlavaloniauiavalonia

Setting window icon in Avalonia


I am writing a small app for as a school project and I cannot figure out how can I change the window icon. I found the "Icon" property of Window, but I have no clue how it works, as I have found little documentation on it. When I tried to input something in the field, it threw an error, that the resource could not be found. I read something on importing resources as well, but this is my first app of this kind, so I am completely lost. Any help much appreciated, thank you


Solution

  • You need to add your icon as AvaloniaResource. If you are using MVVM template, everything in Assets directory should be added as one. If you aren't, then add

    <ItemGroup>
      <AvaloniaResource Include="Assets\**" />
    </ItemGroup>
    

    to your .csproj file. Then put your icon into Assets directory. After that simply writing Icon="/Assets/your-icon.ico" in your window xaml should work.