<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的官方文档,但它充满了错误。当您的项目甚至不能构建时,这并不是很有帮助。
发布于 2021-10-10 21:23:51
您还需要为该属性定义一个getter方法。
public Bitmap getCurrentImage()
{
return CurrentImage;
}https://stackoverflow.com/questions/69519018
复制相似问题