EventAggregator pub/sub message's scope ?

Nov 17, 2010 at 2:50 PM

Hi all,

I have my ShellView below. Basically in my ShellViewModel I set 'ActiveItem' to a VM, let's call it PubVM.  Now , PubVM publishes msgs, let's say of type, MyMsg.  On the receiving end we have the HistoryView user control. This VM implements IHandle<MyMsg>, however, I am not receiving messages in this VM.  While debugging, I hit my Publish breakpoint, but I don't get inside the Handle(...) method of my HistoryViewModel.  I am wondering if the EventAggregator only works in Parent->Child communication, and if so, I may be violating this with my current setup. 

Not sure, any help appreciated ?

 

<UserControl>
    <Grid>...
        <ContentControl Grid.Row="2" Grid.ColumnSpan="2"  x:Name="ActiveItem" />
       <my:HistoryView Grid.Row="3" Grid.ColumnSpan="2" />       
    </Grid>
</UserControl>

 

Coordinator
Nov 17, 2010 at 2:52 PM

Has your ViewModel called Subscribe on the EventAggregator? passing itself as the parameter?

Nov 17, 2010 at 3:01 PM
Edited Nov 17, 2010 at 3:19 PM
EisenbergEffect wrote:

Has your ViewModel called Subscribe on the EventAggregator? passing itself as the parameter?

I did add this to the HistoryViewModel.  However, I think I have a bigger problem. Hate to thread crap my own thread, but how do I instruct Caliburn.Micro to load my HistoryView user control (My VM is not getting created) ?  It is not loading right now, unless I keep the default generated code behind file that looks like this:

 

 public partial class HistoryView : UserControl
    {
        public HistoryView()
        {
            InitializeComponent();
        }
    }

I know this is not the right way.

 

Nov 17, 2010 at 4:16 PM

 

It is working now :) but I did have to refactor my HistoryView user control out into the ShellView :(  I really want to understand why/how I can register a user control from my main view (ShellView is root V/VM).  If it'll help I can create a new thread.  (maybe I am not providing the right facilities for CM to find that HistoryVM )