【问题标题】:Convert Lazy<View> to Lazy<RelayCommand> and back将 Lazy<View> 转换为 Lazy<RelayCommand> 并返回
【发布时间】:2016-11-17 07:28:02
【问题描述】:

我在附加文件时尝试添加描述,并且我使用 MVVM 模型。我创建了一个 commandHolder 并从那里创建了一个命令,但我无法将 Lazy&lt;View&gt; 转换为 Lazy&lt;RelayCommand&gt; 我请求您帮助我。

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

this.fileAttachmentDescriptionViewHolder = new Lazy<RelayCommand>(this.CreateFileAttachmentDescriptionCommand);

我得到错误:

错误 CS0029 无法隐式转换类型 'System.Lazy Path.RelayCommand' 到 'System.Lazy path.View'

【问题讨论】:

  • 似乎您将视图分配给“commandHolder”并将命令分配给“viewHolder”。这没有多大意义。
  • 感谢机械师和凯文
  • @SanthoshRajoo 如果确实回答了您的问题,请点击投票按钮下方的复选标记,随时将答案标记为“答案”。

标签: c# wpf mvvm


【解决方案1】:

我认为你是在倒退,正如机械师评论中所说的那样。

this.fileAttachmentDescriptionCommandHolder = 
    new Lazy<RelayCommand>(this.CreateFileAttachmentDescriptionCommand);

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 2015-05-08
    相关资源
    最近更新 更多