-1

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?

  • Works fine for me https://i.imgur.com/CIa1JWp.png You've probably something ambiant that messes it up, like the `Style` property, etc. – Simon Mourier Jun 12 '23 at 16:49
  • @SimonMourier Nope. I'm using your code, and now I see [this](https://i.stack.imgur.com/5iWIU.png). –  Jun 12 '23 at 19:14
  • Update WinAppSDK to 1.3 and please post a reproducible sample instead of noping people who try to help https://stackoverflow.com/help/minimal-reproducible-example – Simon Mourier Jun 12 '23 at 19:16
  • @SimonMourier Where do I find this info? –  Jun 12 '23 at 23:50
  • [Latest downloads for the Windows App SDK](https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/downloads). It may be that the image file is not properly referenced, you can try to use the default logo image for testing. Can it be displayed normally? `` – Junjie Zhu - MSFT Jun 13 '23 at 02:30

1 Answers1

1

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.
Andrew KeepCoding
  • 7,040
  • 2
  • 14
  • 21