Skip to content

Commit

Permalink
fix: Avoid generating duplicate TabViewItems
Browse files Browse the repository at this point in the history
- Fixes issues #4899 and #4907
- The applied Uno specific workaround is reported as issue #4925
  • Loading branch information
MartinZikmund committed Jan 19, 2021
1 parent 8fa2a49 commit 9c35539
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/TabView/TabView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,11 @@ void OnTabContentPresenterLosingFocus(object sender, LosingFocusEventArgs args)

// It is not ideal to call UpdateLayout here, but it is necessary to ensure that the ContentPresenter has expanded its content
// into the live visual tree.
tabContentPresenter.UpdateLayout();
#if IS_UNO
// TODO: Uno specific - issue #4925 - Calling UpdateLayout here causes another Measure of TabListView, which is already in progress
// if this tab was added by data binding. As a result, two copies of each tab would be constructed.
//tabContentPresenter.UpdateLayout();
#endif

if (shouldMoveFocusToNewTab)
{
Expand Down Expand Up @@ -1144,20 +1148,21 @@ void UpdateSelectedItem()
var listView = m_listView;
if (listView != null)
{
var tvi = SelectedItem as TabViewItem;
if (tvi == null)
{
tvi = ContainerFromItem(SelectedItem) as TabViewItem;
}

if (tvi != null)
{
listView.SelectedItem = tvi;

// Setting ListView.SelectedItem will not work here in all cases.
// The reason why that doesn't work but this does is unknown.
tvi.IsSelected = true;
}
listView.SelectedItem = SelectedItem;
//var tvi = SelectedItem as TabViewItem;
//if (tvi == null)
//{
// tvi = ContainerFromItem(SelectedItem) as TabViewItem;
//}

//if (tvi != null)
//{
// listView.SelectedItem = tvi;

// // Setting ListView.SelectedItem will not work here in all cases.
// // The reason why that doesn't work but this does is unknown.
// tvi.IsSelected = true;
//}
}
}

Expand Down

0 comments on commit 9c35539

Please sign in to comment.