Skip to content

Commit

Permalink
Tabview: Fix issue with newly added items not behaving according to T…
Browse files Browse the repository at this point in the history
…abViews WidthMode (#2752)

* Fix old test that already should have caught this error

* Fix bug with Compact sizing not being applied to newly added items

* Remove unused import
  • Loading branch information
marcelwgn authored Jun 25, 2020
1 parent 1c67178 commit 865e4fc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
32 changes: 24 additions & 8 deletions dev/TabView/APITests/TabViewTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using MUXControlsTestApp.Utilities;
Expand Down Expand Up @@ -46,9 +46,16 @@ public void VerifyCompactTabWidthVisualStates()
tabView.SelectedItem = tabView.TabItems[0];
(tabView.SelectedItem as TabViewItem).IsSelected = true;
Verify.AreEqual("Item 0", (tabView.SelectedItem as TabViewItem).Header);
tabView.TabWidthMode = TabViewWidthMode.Compact;
Content.UpdateLayout();
});
// Waiting for layout
IdleSynchronizer.Wait();

RunOnUIThread.Execute(() =>
{
// Now set tab width mode
tabView.TabWidthMode = TabViewWidthMode.Compact;
});

IdleSynchronizer.Wait();

Expand Down Expand Up @@ -82,14 +89,23 @@ private static void VerifyTabWidthVisualStates(IList<object> items, bool isCompa
foreach (var item in items)
{
var tabItem = item as TabViewItem;
if (tabItem.IsSelected || !isCompact)
{
VisualStateHelper.ContainsVisualState(tabItem, "StandardWidth");
}
else
var rootGrid = VisualTreeHelper.GetChild(tabItem, 0) as FrameworkElement;

foreach (var group in VisualStateManager.GetVisualStateGroups(rootGrid))
{
VisualStateHelper.ContainsVisualState(tabItem, "Compact");
if (group.Name == "TabWidthModes")
{
if(tabItem.IsSelected || !isCompact)
{
Verify.AreEqual("StandardWidth", group.CurrentState.Name, "Verify that this tab item is rendering in standard width");
}
else
{
Verify.AreEqual("Compact", group.CurrentState.Name, "Verify that this tab item is rendering in compact width");
}
}
}

}
}

Expand Down
6 changes: 5 additions & 1 deletion dev/TabView/TabView.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include "pch.h"
Expand Down Expand Up @@ -635,6 +635,10 @@ void TabView::OnItemsChanged(winrt::IInspectable const& item)
}
else
{
if (const auto newItem = TabItems().GetAt(args.Index()).try_as<TabViewItem>())
{
newItem->OnTabViewWidthModeChanged(TabWidthMode());
}
UpdateTabWidths();
}
}
Expand Down
1 change: 1 addition & 0 deletions dev/TabView/TabViewItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void TabViewItem::OnApplyTemplate()
}

UpdateCloseButton();
UpdateWidthModeVisualState();
}

void TabViewItem::OnIsSelectedPropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args)
Expand Down

0 comments on commit 865e4fc

Please sign in to comment.