❔ unable to send messages using MVVMtoolkit messenger

i am trying to pass messages between two viewmodels employeeviewmode and storeviewmodebut it doesn't work
public class StoreViewModel :BaseViewModel
{


public ICommand NavigateEmployeeCommand { get; }
public StoreViewModel(INavigation storeNav)
{
NavigateEmployeeCommand = new NavigateCommand(storeNav);
}


protected override void OnActivated()
{
Messenger.Register<StoreViewModel, MonthNameMessage>(this, (r, m) => r.MonthMessageReceived= m.Value

);
}

private string _monthMessageReceived;
public string MonthMessageReceived { get => _monthMessageReceived;

set => SetProperty(ref _monthMessageReceived, value); }

}

//employee viemodel
public class EmployeeViewModel:BaseViewModel
{

public ICommand NavigateStoreCommand { get; }

public ICommand SendMessageCommand { get; }
public EmployeeViewModel(INavigation storeNav)
{
NavigateStoreCommand = new NavigateCommand(storeNav);

SendMessageCommand= new RelayCommand(SendMessage);

}


private readonly string _testVariable = "Employee haahahah";
public string TestVariable
{
get => _testVariable;


}

protected override void OnActivated()
{
Messenger.Register<EmployeeViewModel, CurrentMonthRequestMessage>(this, (r,m)=> m.Reply(r._testVariable));
}


public void SendMessage()
{
Messenger.Send(new MonthNameMessage(_testVariable));
}

}

//Message classes
public sealed class MonthNameMessage : ValueChangedMessage<string>
{
public MonthNameMessage(string value) : base(value)
{
}
}
public sealed class CurrentMonthRequestMessage:RequestMessage<string>
{

}
public class StoreViewModel :BaseViewModel
{


public ICommand NavigateEmployeeCommand { get; }
public StoreViewModel(INavigation storeNav)
{
NavigateEmployeeCommand = new NavigateCommand(storeNav);
}


protected override void OnActivated()
{
Messenger.Register<StoreViewModel, MonthNameMessage>(this, (r, m) => r.MonthMessageReceived= m.Value

);
}

private string _monthMessageReceived;
public string MonthMessageReceived { get => _monthMessageReceived;

set => SetProperty(ref _monthMessageReceived, value); }

}

//employee viemodel
public class EmployeeViewModel:BaseViewModel
{

public ICommand NavigateStoreCommand { get; }

public ICommand SendMessageCommand { get; }
public EmployeeViewModel(INavigation storeNav)
{
NavigateStoreCommand = new NavigateCommand(storeNav);

SendMessageCommand= new RelayCommand(SendMessage);

}


private readonly string _testVariable = "Employee haahahah";
public string TestVariable
{
get => _testVariable;


}

protected override void OnActivated()
{
Messenger.Register<EmployeeViewModel, CurrentMonthRequestMessage>(this, (r,m)=> m.Reply(r._testVariable));
}


public void SendMessage()
{
Messenger.Send(new MonthNameMessage(_testVariable));
}

}

//Message classes
public sealed class MonthNameMessage : ValueChangedMessage<string>
{
public MonthNameMessage(string value) : base(value)
{
}
}
public sealed class CurrentMonthRequestMessage:RequestMessage<string>
{

}
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server