开发者

tab usercontrol closing event

开发者 https://www.devze.com 2023-03-10 16:11 出处:网络
Hi i have a tab load this usercontrol. when i wish to close this tab, i wish to call this cancelbutton_click event to pop up confirmation on closing, if OK, then close, if Cancel, the tab stays.

Hi i have a tab load this usercontrol. when i wish to close this tab, i wish to call this cancelbutton_click event to pop up confirmation on closing, if OK, then close, if Cancel, the tab stays.

if i use Unloaded event, it will pop up twice before closing.

 private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
              cancelbutton_click(sender,null);
        }

Cancel button:

private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
  MessageBoxResult objResult = MessageBox.Show("\nAre you sure you want to cancel?", "Cancel Confirmation", MessageBoxButton.OKCancel);


            if (objResult == MessageBoxResult.OK)
            {
                try
                {
                    TabItem tabItem = parentWindow.FindTabItemByName(ControlType.BusinessesContractors.ToString(), false);
                    this.parentWindow.mainTabControl.Items.Remove(tabItem);
                    this.parentWindow.statusTextBlock.Text = "Ready";
                }
       开发者_开发技巧         catch (Exception ex)
                {

                }
            }

how to resolve this? thanks


Unloaded is called when the control is already being removed, it's not an event you want to handle often, just create a button which is supposed to close the tab, handle it's click, check if the user wants to cancel via the dialogue and close the tab if he does not.

0

精彩评论

暂无评论...
验证码 换一张
取 消