microsoft/microsoft-ui-xaml
在 GitHub 查看TabView: Closing left-most tab throws exception when IsAddTabButtonVisible = false
Open
#3,849 建立於 2020年12月22日
area-TabViewbughelp wantedteam-Controls
描述
Describe the bug
When closing the left-most tab, calling sender.TabItems.Remove(args.Tab); in the TabCloseRequested event handler
while IsAddTabButtonVisible = false causes a System.ArgumentException.
Steps to reproduce the bug
- Create a TabView with some tabs, set
IsAddTabButtonVisible = falseand create an event handler forTabCloseRequested. - In the
TabCloseRequestedevent handler, callsender.TabItems.Remove(args.Tab);. - Run the app, select the left-most tab, and press the X button to close it.
<muxc:TabView
x:Name="MainTabView"
Width="1490"
Height="980"
HorizontalAlignment="Left"
VerticalAlignment="Center"
IsAddTabButtonVisible="False"
TabCloseRequested="MainTabView_TabCloseRequested">
<muxc:TabViewItem Header="1" />
<muxc:TabViewItem Header="2" />
<muxc:TabViewItem Header="3" />
<muxc:TabViewItem Header="4" />
</muxc:TabView>
private void MainTabView_TabCloseRequested(MUXC.TabView sender, MUXC.TabViewTabCloseRequestedEventArgs args)
{
sender.TabItems.Remove(args.Tab);
}
Expected behavior Expected the left-most tab to close when its X button is pressed. Currently, an exception is thrown instead:
System.ArgumentException
HResult=0x80070057
Message=The parameter is incorrect.
The parameter is incorrect.
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.InteropServices.WindowsRuntime.IVector`1.RemoveAt(UInt32 index)
at System.Runtime.InteropServices.WindowsRuntime.VectorToListAdapter.RemoveAtHelper[T](IVector`1 _this, UInt32 index)
at System.Runtime.InteropServices.WindowsRuntime.VectorToCollectionAdapter.Remove[T](T item)
at App1.MainPage.Tabs_TabCloseRequested(TabView sender, TabViewTabCloseRequestedEventArgs args) in \App1\MainPage.xaml.cs:line 39
Screenshots
Version Info
NuGet package version: Microsoft.UI.Xaml 2.5.0
Windows app type:
| UWP | Win32 |
|---|---|
| Windows 10 version | Saw the problem? |
|---|---|
| Insider Build (xxxxx) | |
| May 2020 Update (19041) | Yes |
| November 2019 Update (18363) | |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) |
| Device form factor | Saw the problem? |
|---|---|
| Desktop | Yes |
| Xbox | |
| Surface Hub | |
| IoT |
Additional context
Current workaround is to set IsAddTabButtonVisible = true before calling sender.TabItems.Remove(args.Tab);:
private void MainTabView_TabCloseRequested(MUXC.TabView sender, MUXC.TabViewTabCloseRequestedEventArgs args)
{
sender.IsAddTabButtonVisible = true;
sender.TabItems.Remove(args.Tab);
sender.IsAddTabButtonVisible = false;
}