【问题标题】:Unable to display image in avalonia无法在 avalonia 中显示图像
【发布时间】:2021-10-10 21:11:06
【问题描述】:
<Image Name="ImageDisplay" 
               Source="{Binding CurrentImage}"
               Grid.Column="1"/>
public class NewWindowViewModel : ViewModelBase, INotifyPropertyChanged
    {
        public Bitmap CurrentImage = new Bitmap(Path.Combine(Environment.CurrentDirectory, @"Assets\LOGO.png"));
    }
public NewWindow()
        {
            InitializeComponent();
            _viewModel = new NewWindowViewModel();
            DataContext = _viewModel;
#if DEBUG
            this.AttachDevTools();
#endif
        }

图片不显示,输出返回错误:[Binding] Error in binding to 'Avalonia.Controls.Image'.'Source': 'Could not find a matching property accessor for 'CurrentImage' on 'RandomProject.ViewModels.NewWindowViewModel''

一切都应该正常工作,但事实并非如此。我是 Avalonia 的新手,我想摆脱仅限于 Windows 的束缚,但我的第一印象并不是很好。

这里有官方文档https://docs.avaloniaui.net/docs/controls/image,但是里面有很多错误。当您的项目甚至无法构建时,这并不完全有帮助。

【问题讨论】:

    标签: c# .net avaloniaui


    【解决方案1】:

    您还需要为此属性定义一个 getter 方法。

    public Bitmap getCurrentImage()
    {
        return CurrentImage;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-24
      • 2012-06-16
      • 2021-02-28
      • 2020-02-19
      • 2018-08-02
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多