Xamarin Android - 关闭 DialogFragment

Xamarin Android - Dismiss DialogFragment

我查看了几个不同的线程来了解如何关闭 DialogFragment,但似乎对我没有任何作用。当我从我拥有的点击事件切换到新的 Activity 时,我希望能够关闭 DialogFragment。我尝试使用单击事件中的 this.Activity.Dismiss() 之类的东西,但也从我显示 DialogFragment 的地方尝试了这个:

if (_exportFragment != null)
            {
                _exportFragment.Dismiss();
            }

但其中 none 似乎有效。

编辑

这是我显示 DialogFragment 的地方:

gridview.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args)
            {
                // DIALOG FRAGMENT
                FragmentTransaction ft = FragmentManager.BeginTransaction();
                //Remove fragment else it will crash as it is already added to backstack
                Fragment prev = FragmentManager.FindFragmentByTag("dialog");
                if (prev != null)
                {
                    ft.Remove(prev);
                }

                ft.AddToBackStack(null);

                // Create and show the dialog.
                _exportFragment = new VideoExportDialogFragment();
                _exportFragment.VideoCreationDate = VideoList[args.Position].CreationDate;
                //_exportFragment.
                _exportFragment.VideoPathFragment = VideoListPosition(args.Position);

                //_exportFragment.ThumbnailActivity = this;
                //Add fragment
                _exportFragment.Show(ft, "dialog");
                dismissLoader();
            };
        }

        private void dismissLoader()
        {
            if (_exportFragment != null)
            {
                _exportFragment.Dismiss();
            }
        }

I want to be able to close the DialogFragment when I switch to a new Activity from the click event that I have.

在这个点击事件中,您可以使用FindFragmentByTag("dialog")方法找到您要关闭的dialogFragment,然后您可以使用_exportFragment.Dismiss()关闭这个DialogFragment .像这样的代码:

bt.Click += (sender, e) =>
{
     MyDialogFragment _exportFragment = (MyDialogFragment)FragmentManager.FindFragmentByTag("dialog");
     if (_exportFragment != null)
     {
           _exportFragment.Dismiss();
     }
     //StartActivity(you);
};