ButchersBoy / Dragablz

Dragable and tearable tab control for WPF
http://dragablz.net
MIT License
2.17k stars 320 forks source link

how to handle Default close button #244

Open bheemasekharj opened 3 years ago

bheemasekharj commented 3 years ago

I am using dragablz SetDefaultCloseButton as true. But before closing the tab i want to check some conditions. How to handle close button for tab. I am creating dynamic tab items with some data inside tab control

jraypdx commented 3 years ago

Implement the Dragablz ClosingTabItemHandlerImpl in your window ViewModel ex:

private static void ClosingTabItemHandlerImpl(ItemActionCallbackArgs args) { //in here you can dispose stuff or cancel the close

  //here's your view model:
  var viewModel = args.DragablzItem.DataContext as HeaderedItemViewModel;
  System.Diagnostics.Debug.Assert(viewModel != null);

   if (....)
        //Do something here like prompt the user if they are sure they want to close the tab, checking conditions, etc
  else
        //here's how you can cancel stuff (cancel the tab from being closed):
        //args.Cancel(); 

}

If all you need to do is check some stuff before closing then you can leave out the if/else and the args.Cancel().