Xamarin关闭弹出窗口

时间:2017-10-03 14:07:17

标签: c# android xamarin native

我有一个问题,当SavedAyasListView_ItemLongClick事件触发时,弹出窗口出现一些按钮,我的意图是每当我点击btnDeleteAya按钮,执行一些操作并关闭弹出窗口。 当事件触发时,弹出窗口出现,当我单击btnDeleteAya时,操作将被执行并且弹出窗口消失,但是当我再次执行相同的操作时,弹出窗口不会被关闭。 我希望每次单击btnDeleteAya按钮时关闭它,而不是只需单击外部,因为该部分按预期工作。 这是代码:

        public string itemclicked;
        PopupWindow mpopup;
        private void SavedAyasListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e)
        {
            View popUpView = LayoutInflater.Inflate(Resource.Layout.SavedAyasPopupMenu,
            null); // inflating popup layout
            mpopup = new PopupWindow(popUpView, 800, 500); // Creation of popup
            mpopup.SetBackgroundDrawable(new BitmapDrawable());
            mpopup.OutsideTouchable = true;
            mpopup.Focusable = true;
            mpopup.ShowAtLocation(popUpView, GravityFlags.Center, 10, 50);
            itemclicked = savedAyasListView.GetItemAtPosition(e.Position).ToString();

            Button btnDeleteAya = popUpView.FindViewById<Button>(Resource.Id.btnDeleteAya);
            btnDeleteAya.Click += BtnDeleteAya_Click;
            btnDeleteAya.Click += delegate
            {
                mpopup.Dismiss();
            };

            Button fbShareSavedAya = popUpView.FindViewById<Button>(Resource.Id.fbShareSavedAya);
            fbShareSavedAya.Click += FbShareSavedAya_Click;

        }

0 个答案:

没有答案