microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.3k stars 675 forks source link

Proposal: Add CloseCommand for TabViewItem #1246

Open eugenegff opened 5 years ago

eugenegff commented 5 years ago

Proposal: Add CloseCommand for TabViewItem for MVVM scenarios

Summary

TabView has TabItems property and AddTabButtonClick, TabCloseRequested events to facilitate tabs enumeration/adding/closing. For MVVM scenarios there are bindable properties TabItemsSource, AddTabButtonCommand, AddTabButtonCommandParameter, but there are no CloseCommand nor any other MVVM compatible way to close tab. Writing code instead of such binding is complicated if UI is decoupled from Model layer, quite possibly living in different DLLs that are not depended on each other

Rationale

Scope

Capability Priority
This proposal will allow developers to accomplish W Must
This proposal will allow end users to accomplish X Should
This proposal will allow developers to accomplish Y Could
This proposal will allow end users to accomplish Z Won't

Important Notes

Open Questions

stmoy commented 5 years ago

Thank you for opening this issues @eugenegff ! I think this is a reasonable request. One clarifying question - would it be beneficial to have CloseRequestedCommand (or whatever we call it) on both TabView and TabViewItem? Or does it only need to be on one or the other?

eugenegff commented 5 years ago

I think it would be inconvenient to have it on TabView, as there are no context, which tab is closing. On the other hand, for TabViewItem the item is DataContext, so everything is possible. Therefore I do not see much value in having it in TabView or both places - only in TabViewItem.

Much more interesting would be to react on CanExecute to use it together/instead of TabViewItem::IsClosable. Probably tab should be closable if IsClosable && (!closeCmd || closeCmd->CanExecute(closeCmdParam))