将 Lazy 转换为 Lazy 然后返回

本文关键字:Lazy 然后 返回 RelayCommand 转换 View | 更新日期: 2023-09-27 17:56:51

我正在尝试在附加文件时添加描述,并且我使用MVVM模型。我创建了一个命令持有人,然后从那里创建了一个命令,但我无法将Lazy<View>转换为Lazy<RelayCommand>我请求您帮助我。

this.fileAttachmentDescriptionCommandHolder = new Lazy<FileAttachmentDescriptionView>(() => new FileAttachmentDescriptionView { DataContext = this });
this.fileAttachmentDescriptionViewHolder = new Lazy<RelayCommand>(this.CreateFileAttachmentDescriptionCommand);

我收到错误:

错误 CS0029 无法隐式转换类型"系统.懒惰 Path.RelayCommand' 到 'System.Lazy path.查看'

将 Lazy<View> 转换为 Lazy<RelayCommand> 然后返回

我认为您是在倒退,正如机械师的评论中所述。

this.fileAttachmentDescriptionCommandHolder = 
    new Lazy<RelayCommand>(this.CreateFileAttachmentDescriptionCommand);
this.fileAttachmentDescriptionViewHolder = 
    new Lazy<FileAttachmentDescriptionView>(
        () => new FileAttachmentDescriptionView { DataContext = this });