Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在xamarin中为多平台创建按钮关闭屏幕?_Xamarin_Xamarin.forms - Fatal编程技术网

如何在xamarin中为多平台创建按钮关闭屏幕?

如何在xamarin中为多平台创建按钮关闭屏幕?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,这是MainPage.xaml: <StackLayout > <!-- Place new controls here --> <Label Text="LOGIN" HorizontalOptions="Center" /> <Label Text="Email:" /> <Entry x:Name="txtEmail" Margin = "0, -

这是MainPage.xaml:

<StackLayout >
        <!-- Place new controls here -->
        <Label Text="LOGIN" 
           HorizontalOptions="Center" />
        <Label Text="Email:" />
        <Entry x:Name="txtEmail"  Margin = "0, -5,0,0"  />
        <Label Text="Password:" />
        <Entry x:Name="txtPassword"  Margin = "0, -5,0,0" />
        <Button x:Name="btnLogin" Text="Login"/>
        <Button x:Name="btnClose" Text="Close" Clicked="OnClose"/>
    </StackLayout>
如何关闭多平台(Android、ios、UWP)的目标屏幕?
谢谢大家。

对于您提到的场景,您应该按照接口编码,在Xamarin.Forms项目中创建一个接口,然后在您支持的所有平台中实现该接口

考虑到您想要关闭应用程序本身,请参考下面的架构,这可能会对您有所帮助。您可以根据您的业务案例对其进行相应的修改

Public Interface IPerformPlatformSpecificOperations
{
  void CloseApplication();
}

Android:

Public Class AndroidSpecificOperations : IPerformPlatformSpecificOperations
{
   public void CloseApplication()
   {
     //Platform Specific Code
   }
}

UWP: 

Public Class UWPSpecificOperations : IPerformPlatformSpecificOperations
{
   public void CloseApplication()
   {
     //Platform Specific Code
   }
}

iOS:

Public Class iOSSpecificOperations : IPerformPlatformSpecificOperations
{
   public void CloseApplication()
   {
     //Platform Specific Code
   }
}

使用一些IoC库注入依赖项,然后在Xamarin.Forms项目中调用
CloseApplication()

诚然,我不太清楚你在说什么。您想关闭整个应用程序,还是只关闭
主页
。对于这封信:在关闭
主页后应该显示什么?我只想关闭主页。例如:在android中调用finish()嗨,在android中:我使用finish()函数,但在IOS中存在函数支持?对于IOS,没有直接退出应用程序的方法,但您可以尝试
Public Interface IPerformPlatformSpecificOperations
{
  void CloseApplication();
}

Android:

Public Class AndroidSpecificOperations : IPerformPlatformSpecificOperations
{
   public void CloseApplication()
   {
     //Platform Specific Code
   }
}

UWP: 

Public Class UWPSpecificOperations : IPerformPlatformSpecificOperations
{
   public void CloseApplication()
   {
     //Platform Specific Code
   }
}

iOS:

Public Class iOSSpecificOperations : IPerformPlatformSpecificOperations
{
   public void CloseApplication()
   {
     //Platform Specific Code
   }
}