GetEvent< SetObjectEvent>找不到(缺少指令/参考?)-我在做什么错..? [英] GetEvent<SetObjectEvent> could not be found (missing directive/reference?) - what am I doing wrong ..?

查看:89
本文介绍了GetEvent< SetObjectEvent>找不到(缺少指令/参考?)-我在做什么错..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试构建一个eventaggregator来将我的object的属性从MainViewModel转移到SectionViewModel时,我尝试了以下多篇文章( 3

编辑;正如此答案暗示我认为错不是问题,我改写我的问题以更准确地描述(?)我的问题.

编辑;根据要求SetObjectEvent类

public class SetObjectEvent<TRequest> : PubSubEvent<SetObjectEvent<TRequest>> where TRequest : IObject {}

源自这篇SO文章

编辑;将其更改为

public class SetObjectEvent : PubSubEvent<Object> {}

如在多条注释中所建议的

GetEvent<SetObjectEvent>()GetEvent<SetObjectEvent<Object>>()

上给了我相同的参数例外

解决方案

事实证明,问题出在何处(还有一点如何*)

我将SetObjectEvent放置在models指令中,因为我认为它是Event的模型.我假设可以在MainViewModel名称空间中使用using MyProject.MyModule.Models;正确引用它.原来,我在浏览有关EventAggragator的更多SO文章时错了. SetObjectEvent应该作为namespace MyProject.MyModule.SetObjectEvent坐在模块名称空间中.

*貌似应该是公共类SetObjectEvent:PubSubEvent {} – dvorn

While trying to build an eventaggregator to have the properties of my object be transfered from MainViewModel to SectionViewModel I've tried following multiple articles (1, 2, 3 and 4 ) as to how this works, but I seem to be missing a step..?

In the MainViewModel I have;

protected readonly IEventAggregator eventAggregator;
public MainViewModel(IMainViewModel mainViewModel, IEventAggregator eventAggregator)
{
    ...Some other Code...
    this.eventAggregator = eventAggegator;
}

public Object Object
{
    ...Getter...
    set
    {
        this.object = value;
        this.RaisePropertyChanged();
        this.EventAggregator.GetEvent<SetObjectEvent<Object>>().Publish(this.Object);
    }
}

and in the SectionViewModel I have;

protected readonly IEventAggregator eventAggregator;
public SectionViewModel(ISectionViewModel sectionViewModel, IEventAggregator eventAggregator)
{
    this.eventAggregator = eventAggregator;;
    this.eventAggregator.GetEvent<SetObjectEvent<Object>>().Subscribe((object) => { this.Object = object; });
}

Whom both throw the argument excpetion The type or namespace name 'SetObjectEvent<>' could not be found. I thought this was because I needed a global EventAggregator but someone pointed out this is not the case.

This is the giste of most of the articles, which (to me at least) does not look like it's causing any problems. It all seems pretty logical to me, and I understand what it's supposed to do. However, none of the articles seem to actually be defining the 'SetObjectEvent' Event? Instead the create some sort of general EventAggregate and that's it. That's where I kind of lose track on what's happening. To me it sounds pretty logical I'll need to have a class something like 'Events' that can hold all the different callable events in the project, but I'd have no idea as to how to accomplish this ?

Edit; As this answer implied that what I think is wrong is not the problem, I rephrased my question to more accurately (?) describe my problem.

Edit; As requested the SetObjectEvent class

public class SetObjectEvent<TRequest> : PubSubEvent<SetObjectEvent<TRequest>> where TRequest : IObject {}

derived from this SO article

Edit; changing it to

public class SetObjectEvent : PubSubEvent<Object> {}

as suggested in multiple comments gives me the same argument exception on both GetEvent<SetObjectEvent>() and GetEvent<SetObjectEvent<Object>>()

解决方案

As turns out, the problem was where (and just a little bit how*)

I had the SetObjectEvent placed in the models directive because I figured it was a model for the Event. I assumed it'd be referenced properly with using MyProject.MyModule.Models; within the MainViewModel namespace. Turns out I was wrong while browsing some more SO articles regarding the EventAggragator. The SetObjectEvent should be sitting in the module namespace as namespace MyProject.MyModule.SetObjectEvent.

*Seemingly it should be public class SetObjectEvent: PubSubEvent {} – dvorn

这篇关于GetEvent&lt; SetObjectEvent&gt;找不到(缺少指令/参考?)-我在做什么错..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆