[英]Wrong item selection in ListBox (Windows Phone, Caliburn.Micro, Rx)
[英]Facebook authentication callback on Windows Phone using Caliburn.Micro
我正在借助Caliburn.Micro框架开发Windows Phone应用。 我正在尝试使用本教程实现Facebook登录。
ContinuationManager
导致我遇到问题,因为它假定不使用MVVM模型,而是将整个代码保留在视图的后面。 有没有一种干净的方法来重现控件并将WebAuthenticationBrokerContinuationEventArgs
传递给LogInViewModel
(而不是LogInView
),以便身份验证过程可以继续?
换句话说,如何在用户成功完成Facebook登录过程后在LogInViewModel
调用public async void ContinueWithWebAuthenticationBroker( WebAuthenticationBrokerContinuationEventArgs args)
方法?
有几种方法可以使这个工作,让我给你我的...
我需要与第3 IWebAuthenticationContinuable
OAuth连接,并且为了与该方进行所有通信,我创建了一个Service class
-该类实现了IWebAuthenticationContinuable
接口。 换句话说,所有API调用都在其中,还有ContinueWebAuthentication
方法。 在ContinueWebAuthentication方法内部,我调用一个Status事件-在Service类上也声明了该事件,以将OAuth处理的实际结果状态通知给所有侦听器。
因此,剩下要做的就是在ViewModel中注册该事件,您将在该事件中启动OAuth流程的开始并根据状态更改进行操作,以验证OAuth流程是否正常。 通过触发一个方法(在我的服务类别中为GetAccessToken()方法)来启动实际的OAuth流程,然后在此方法中启动WebuthenticationBroker.AuthenticateAndContinue()
方法。
其他解决方案是使用MVVM消息传递而不是真实事件。 但这仅仅是语义。
我正在使用Caliburn,并且最近实现了Facebook登录。
在我的LoginViewModel中,我调用WebAuthenticationBroker.AuthenticateAndContinue(url);
启动登录。
在App.xaml.cs中,我重写OnActivated方法,检查参数是否来自身份验证代理,如果是,则将其作为消息发送。
protected override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args);
switch (args.Kind)
{
case ActivationKind.WebAuthenticationBrokerContinuation:
OnWebAuthenticationBrokerContinuation((WebAuthenticationBrokerContinuationEventArgs)args);
break;
}
}
private void OnWebAuthenticationBrokerContinuation(WebAuthenticationBrokerContinuationEventArgs args)
{
var eventAggregator = container.GetInstance<IEventAggregator>()
eventAggregator.PublishOnUIThread(args);
}
我的LoginViewModel实现了IHandle<WebAuthenticationBrokerContinuationEventArgs>
并在Handle(WebAuthenticationBrokerContinuationEventArgs message)
获取Facebook令牌并使用该服务进行实际登录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.