I am learning WPF with Caliburn Micro. I have read the documentation many times and I am even following tutorial on YouTube by Timcorey. Somewhere along the line I must have not specified/initialized something correctly.
Normally I would specify the object as X obj = new X(); but in this case the eventaggregator does not like it. I did manage to get the code to run by changing the events.subscribe line to :
if (_events != null) _events.Subscribe(this)
but during runtime the code never reaches this line even when a breakpoint is set. With all the eventaggregator code removed, I can run and trigger my events. I just can't seem to publish and subscribe to it.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PropertyChanged;
using Caliburn.Micro;
using ERP101.EventModels;
using ERP101.ViewModels;
namespace ERP101.ViewModels
{
[AddINotifyPropertyChangedInterface]
public class ShellViewModel : Conductor<object>,IHandle<LoginEvent>
{
private IEventAggregator _events;
private StartPageViewModel _startPVM;
private SimpleContainer _container;
public ShellViewModel(IEventAggregator events,StartPageViewModel startPVM,SimpleContainer container)
{
_events = events;
_events.Subscribe(this); //null reference error here
_startPVM = startPVM;
_container = container;
ActivateItem(_container.GetInstance<LoginViewModel>());
}
public void Handle(LoginEvent message)
{
ActivateItem(_startPVM);
}
}
}```
IEventAggregator events
is apparently null. We can't say why, that code isn't part of the question. – user47589