Search code examples
imagexamlbuttonwinui-3

Images not showing in WinUI 3 Button


I can't seem to make my WinUI 3 Button display an image.

My project is a packaged C# WinUI 3 desktop application.

Here is my XAML code (copied almost directly from the Microsoft docs):

<Button Style="{StaticResource AccentButtonStyle}" AutomationProperties.Name="Pie">
    <StackPanel>
        <Image Source="/Assets/settings-gear.png" Height="52"/>
        <TextBlock Text="Slices" Foreground="Black" HorizontalAlignment="Center"/>
    </StackPanel>
</Button>

And I'm not using any C# code on it, so that isn't the problem.

Yet my button looks like this:
Button screenshot

Here's the .png file I'm using as an icon: Icon

What could be going wrong here?


Solution

  • Try these steps:

    1. Go to the Solution Explorer and right-click settings-gear.png and select Properties.
    2. In the Properties section, change the Build Action from None to Content.