I have a Xamarin.Forms application using FreshMVVM. Can anybody tell me if I can use binding to handle changing the PageModel in Page's code-behind? E.g. if an event happens in the PageModel like this:
public class VideoCallPageModel : BasePageModel
{
SignalRService signalR;
...
public async override void Init(object initData)
{
base.Init(initData);
signalR = new SignalRService();
signalR.OnIncomingCall += SignalR_IncomingCall;
...
private void SignalR_IncomingCall(object sender, VideoCallPeer peer)
{
...
}
So I need to handle in Page's code-behind firing this OnIncomingCall event. Is it possible?
define a custom event in your model
public delegate void IncomingCallHandler(object sender, VideoCallPeer e);
public event IncomingCallHandler OnIncomingCall;
private void SignalR_IncomingCall(object sender, VideoCallPeer peer)
{
if (OnIncomingCall == null) return;
OnIncomingCall(this, peer);
}
then your page can subscribe to it with an event handler