0

I used caliburn.micro version 4.0.173 and .NET framework 4.8.

Requirement is as below description I have a script ViewModel. There is a button to click it and pop up a setting ViewModel. After setting ViewModel appear, it can be setup some parameters and click button to confirm these settings. When confirm button is clicked, it can trigger to script ViewModel from setting ViewModel. I refer this link to do this. To create a class is for event in project folder. But, when I publish in setting View, that doesn't work to subscribe in Handle of script viewmodel. How can I pass these parameters to another view model? Thank you.

Event

public class FooEvent
{
    public bool Foo { get; set; }
    public FooEvent(bool foo)
    {
        Foo = foo;
    }
}

Setting ViewModel

public class SettingViewModel : Screen
{
    private IEventAggregator _eventAggregator;
    public ItemViewModel(IEventAggregator eventAggregator)
    {
        _eventAggregator = eventAggregator;
    }

    public void PublishFooEvent()
    {
        _eventAggregator.PublishOnUIThreadAsync(new FooEvent(true));
    }

    public void BtnSaveItem()
    {
        PublishFooEvent();
    }
}

Script ViewModel

public class ScriptViewModel : Screen, IHandle<FooEvent>
{
    private readonly IEventAggregator _eventAggregator;

    [ImportingConstructor]
    public ScriptViewModel(IEventAggregator eventAggregator)
    {
        this._eventAggregator = eventAggregator; 

        _eventAggregator.SubscribeOnUIThread(this);
    }

    public void Handle(FooEvent fooEvent)
    {

    }
}
Ben Pai
  • 1
  • 2

1 Answers1

0

I find out that problem is in other handle. When I added interface and fixed error automatically. IDE creates a new method (HandleAsync) which I didn't notice it. Therefore, I type another handle manually. It always works on HandleAsync after trigger with another viewmodel.

Ben Pai
  • 1
  • 2