Search code examples
xamlwinuiwinui-3

What is the proper way to reference an image in winui


I am trying to display an image using the latest version of winui, without success. Due to my lack of progress I assume I must be doing something terribly wrong, however, I can't determine what that might be.

Here is my most recent attempt.

MainWindow.xaml:

<Image Source="AppIcon.png" Width="200" Height="200" ImageFailed="ImageFailed_Event"/>

Image


Solution

  • Ok here is the solution that I have found with the help of the people in the comments:

    • Set the "Build Action" of the image file to "Content"
    • Set the "Copy to Output Directory" to "Copy if newer"

    This is all that is necessary, no URI magic is needed.