Search code examples
c#winui-3windows-community-toolkit

WinUI Community Toolkit Carousel not displaying items


I have a WinUI 3 project in which I installed the Windows Community Toolkit for WinUI (the common, WinUI, WinUI UI and Layout Controls packages) and I use the Carousel from the CommunityToolkit.WinUI.UI.Controls.Layout package. However, when I add any items to it, they simply do not show up on the carousel. I set the background colour to red to confirm the carousel does indeed show and the result sure is a massive red box, but no images on it. I followed the example for UWP that can be found here. I know UWP is obviously not the same as WinUI, but they are certainly similar, and I couldn't find an example for WinUI.

The source code can be found here (the repo is on a private server, so I cannot share that link).

The Carousel control can be found in the MainWindow, the items list contains an instance of ChessClientGame and CheckersClientGame, but neither show up in the carousel, even though the source of the image in the carousel is bound to the IconPath property which is set to a valid image resource in both games.

I tried both binding the source to IconPath property and setting the Source directly to an image (such as /Resources/Images/GameIcons/ChessIcon.png), but in neither case anything actually showed up in the carousel. What I expected to happen was seeing two images in the carousel that I could select.


Solution

  • Turns out I simply did not set the build action of the images to 'Content'. Doing so fixed it, so nothing is wrong with the carousel code.