AvaloniaUI/Documentation

Button documentation shows wrong Bitmap creation in xaml

ylatuya opened this issue · 4 comments

Describe the bug

Adding a Bitmap to Resources following the example https://docs.avaloniaui.net/docs/controls/button#play-button ends with a compilation error

    <Application.Resources>
        <Bitmap x:key="Play">/Assets/Player/Play.png</Bitmap>
        <Bitmap x:key="Pause">/Assets/Player/Pause.png</Bitmap>
    </Application.Resources>

App.axaml(30,30): Error XAMLIL: No Content property or any Add methods found for type Avalonia.Visuals:Avalonia.Media.Imaging.Bitmap Line 13, position 30. (XAMLIL)

To Reproduce
Steps to reproduce the behavior:

  1. Follow the linked documentation example
  2. Build
  3. See compilation error

Expected behavior
The XAML translates to:

var assets = AvaloniaLocator.Current.GetService<IAssetLoader>()!;
Resources["Play"] = new Bitmap(assets.Open(new Uri("/Assets/Player/play.png")));

Additional context
Avalonia 1.10.13

Wrong syntax. Bitmap needs a ctor parameter.
See AvaloniaUI/Avalonia#5659 (comment) how to do so

Thanks. Should I create a new PR to update the documentation?

Yes, documentation is wrong here