Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
C# 有没有像安卓那样的方法';s Finish()在Xamarin表单中?_C#_Xamarin_Xamarin.forms - Fatal编程技术网

C# 有没有像安卓那样的方法';s Finish()在Xamarin表单中?

C# 有没有像安卓那样的方法';s Finish()在Xamarin表单中?,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我正在寻找一种方法,当我浏览不同的页面时,它将结束以前的页面/活动,这样当按下“后退”按钮时,它就不会返回到以前的消息。在Java Android中,这样的方法称为finish(),那么Xamarin跨平台中是否有这样的方法呢?在Android的Xamarin表单上,您有一个类似的方法:() 我认为您找到了这种方法?Xamarin Forms有一些选项可以从堆栈中删除或向堆栈中添加页面。查看Navigation.PopAsync或Navigation.RemovePage在xamarin表单中没

我正在寻找一种方法,当我浏览不同的页面时,它将结束以前的页面/活动,这样当按下“后退”按钮时,它就不会返回到以前的消息。在Java Android中,这样的方法称为finish(),那么Xamarin跨平台中是否有这样的方法呢?

在Android的Xamarin表单上,您有一个类似的方法:()


我认为您找到了这种方法?

Xamarin Forms有一些选项可以从堆栈中删除或向堆栈中添加页面。查看
Navigation.PopAsync
Navigation.RemovePage
在xamarin表单中没有方法finish,因为finish()是让系统知道程序员希望完成当前活动。在xamarin表单中,您只有一个活动,即MainActivity。Xamarin表单以导航为中心,因此如果您想返回到以前的Navigation Navigation.PopAsync,或者如果您想关闭一个模式,请使用Navigation.popmodel

基于您对目标的描述,我认为
this.Finish()将像一个符咒一样工作

示例代码:

Button nextPage;
protected override void OnCreate(Bundle savedInstanceState)
    {
        try
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.your_content_xml);
            // Set our view from the "main" layout resource

            nextPage = FindViewById<Button>(Resource.Id.button1);

            nextPage.Click += (s, e) =>
            {
                Intent nextActivity = new Intent(this, typeof(next_page_CS_file)); // Create Intent instance
                StartActivity(nextActivity); // Go to the Next Page as set in Intent
                this.Finish(); // Terminates Current Page.
                               // As such, once you're in the next page, clicking the back button 
                               // on phone's menu will close the App instead of going back here
            };
        } catch (Exception ex)
        {
            // Any code you want that'll handle the Exception.
            // Like, for example, . . .
            Toast.MakeText(this, ex.ToString(), ToastLength.Short).Show();
        }
    }
按钮下一页;
创建时受保护的覆盖无效(Bundle savedInstanceState)
{
尝试
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(这个,savedInstanceState);
SetContentView(Resource.Layout.your_content_xml);
//从“主”布局资源设置视图
nextPage=findviewbyd(Resource.Id.button1);
下一页。单击+=(s,e)=>
{
Intent nextractivity=new Intent(this,typeof(next_page_CS_file));//创建Intent实例
StartActivity(nextActivity);//按照Intent中的设置转到下一页
this.Finish();//终止当前页。
//因此,进入下一页后,单击“上一步”按钮
//手机上的菜单将关闭应用程序,而不是返回此处
};
}捕获(例外情况除外)
{
//您需要的任何处理异常的代码。
//比如说。
Toast.MakeText(this,例如ToString(),ToastLength.Short).Show();
}
}

根据我的理解和经验,这应该是可行的。但是我不确定是否还有其他方法可以实现您的目标。

WPF和Xamarin是完全不同的技术,请不要将它们混合在一起。您甚至没有用谷歌搜索它吗@Vucko我问过,如果你查对了,我没有问关于Xamarin AndroidNot Xamarin for android的问题,我使用的是portable Classis如果你使用的是portable class,那就意味着你可能有自己的导航服务。只需让您的ViewModels实现IDisposable,并将方法NavigateAndReset添加到您的导航服务中,即可清除堆栈并处理ViewModels。这就是全部