Prism Event Aggregator-无法读取方法

时间:2019-02-19 07:18:54

标签: c# mvvm prism eventaggregator

我已经做了一段时间的Wpf程序了。但是当我创建一个应用程序并创建多个viewmodel时。而且我需要在其他视图模型中访问属性。

因此为了访问它。我需要每个视图模型都是静态的。

然后我搜索了视图模型应该如何相互通信。

然后我在这里找到了答案

https://stackoverflow.com/questions/4892731/wpf-mvvm-how-do-viewmodels-communicate-with-each-other

因此我搜索了棱镜聚合器,并找到了一个教程

https://www.c-sharpcorner.com/UploadFile/5ffb84/prism-event-aggregator-in-wpf-with-mvvm/

然后我跟随它。

就像本教程一样。我在“模型”文件夹中添加了一个event class

这是代码

namespace MdbMerge.Model
{
   public sealed class Event
    {
        #region Class Properties

        internal static Event EventInstance
        {
            get
            {
                return eventInstance;
            }
        }

        #endregion

        #region Instance Properties

        internal IEventAggregator EventAggregator
        {
            get
            {
                if (eventAggregator == null)
                {
                    eventAggregator = new EventAggregator();
                }

                return eventAggregator;
            }
        }

        #endregion

        #region Constructors

        private Event()
        {

        }

        #endregion

        #region Class Fields

        private static readonly Event eventInstance = new Event();

        #endregion

        #region Instance Fields

        private IEventAggregator eventAggregator;

        #endregion

    }
}

但是当我设置视图模型的datacontext时,会给我错误

DataContext = new MdbMergeViewModel(MdbMerge.Model.Event.EventInstance.EventAggregator);

它说。 MdbMerge does not contain a definition for model.

那我该如何解决呢?

为什么不读取里面的方法?

enter image description here

这是我的程序结构的屏幕截图

enter image description here

谢谢。

0 个答案:

没有答案