Fixed issue navigating away and back to tab view

This commit is contained in:
watsonb8
2019-12-23 19:06:03 -05:00
parent f691deab6a
commit 109457d6fa
3 changed files with 34 additions and 7 deletions

View File

@ -153,7 +153,7 @@ namespace Aurora.Design.Components.TabView
}
}
SetCurrentTab(0, true);
SetCurrentTab(SelectedTabIndex, true);
}
}
@ -439,7 +439,13 @@ namespace Aurora.Design.Components.TabView
#endregion
#region SelectedTabIndex
public static readonly BindableProperty SelectedTabIndexProperty = BindableProperty.Create(nameof(SelectedTabIndex), typeof(int), typeof(TabViewControl), 0, propertyChanged: OnSelectedTabIndexChanged);
public static readonly BindableProperty SelectedTabIndexProperty = BindableProperty.Create(
nameof(SelectedTabIndex),
typeof(int),
typeof(TabViewControl),
defaultValue: 0,
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: OnSelectedTabIndexChanged);
private static void OnSelectedTabIndexChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is TabViewControl tabViewControl && tabViewControl.ItemSource != null)
@ -477,14 +483,25 @@ namespace Aurora.Design.Components.TabView
if (((position >= 0 && position < ItemSource.Count) || initialRun))
{
if (oldPosition < ItemSource.Count && _mainContainerSL.Children.Count == 2)
if (oldPosition < ItemSource.Count)
{
ItemSource[oldPosition].IsCurrent = false;
//Remove second child
_mainContainerSL.Children.RemoveAt(1);
List<bool> tabActiveList = ItemSource.Select((TabItem tab, int index) =>
{
return index == position;
})
.ToList();
for (int i = 0; i < tabActiveList.Count(); i++)
{
ItemSource[i].IsCurrent = tabActiveList[i];
}
// Remove second child
if (_mainContainerSL.Children.Count == 2)
{
_mainContainerSL.Children.RemoveAt(1);
}
}
_mainContainerSL.Children.Add(ItemSource[position].Content);
ItemSource[position].IsCurrent = true;
SelectedTabIndex = position;
Device.BeginInvokeOnMainThread(async () => await _tabHeadersContainerSv.ScrollToAsync(_headerContainerGrid.Children[position], ScrollToPosition.MakeVisible, false));