2014-07-05 78 views

回答

4

我不相信功能是在Xamarin.Forms呢。你可以安裝Xamarin.Forms.Labs(在NuGet上可用)並從XFormsApplicationDelegate繼承你的應用程序委託。您可以查看GitHub源文件上的sample app delegate

public partial class AppDelegate : XFormsApplicationDelegate 
{ 

你會那麼需要用DI容器註冊IXFormsApp接口:

private void SetIoc() 
    { 
     var resolverContainer = new SimpleContainer(); 

     var app = new XFormsAppiOS(); 
     app.Init(this); 

     resolverContainer.Register<IXFormsApp>(app); 

     Resolver.SetResolver(resolverContainer.GetResolver()); 
    } 

一旦應用程序已被註冊,你會用它在你的共享/ PCL代碼通過對DI容器上解析器。您將訂閱恢復和暫停事件。 Sample here.

 var app = Resolver.Resolve<IXFormsApp>(); 
     if (app == null) 
     { 
      return; 
     } 

     app.Closing += (o, e) => Debug.WriteLine("Application Closing"); 
     app.Error += (o, e) => Debug.WriteLine("Application Error"); 
     app.Initialize += (o, e) => Debug.WriteLine("Application Initialized"); 
     app.Resumed += (o, e) => Debug.WriteLine("Application Resumed"); 
     app.Rotation += (o, e) => Debug.WriteLine("Application Rotated"); 
     app.Startup += (o, e) => Debug.WriteLine("Application Startup"); 
     app.Suspended += (o, e) => Debug.WriteLine("Application Suspended"); 
+0

謝謝@SKall這工作完美! – dmc

+0

謝謝 - 我錯誤地嘗試用DependencyService來解析IXFormsApp,它的工作機會幾乎爲零。 –

相關問題