private static void TryStartPivotHeaderAnimation(Pivot pivot, object NewItem, object OldItem) { if (NewItem == null) { return; } var NewIndex = -1; var OldIndex = -1; if (pivot.ContainerFromItem(OldItem) is PivotItem oldContainer) { OldIndex = pivot.IndexFromContainer(oldContainer); } if (pivot.ContainerFromItem(NewItem) is PivotItem newContainer) { NewIndex = pivot.IndexFromContainer(newContainer); } if (NewIndex >= 0) { var name = GetName(pivot); var Headers = pivot.VisualTreeFindAll <PivotHeaderPanel>(); var Header = Headers.FirstOrDefault(c => c.Name == "Header"); var StaticHeader = Headers.FirstOrDefault(c => c.Name == "StaticHeader"); var newIndicator = GetPivotHeaderIndicator(Header, name, NewIndex); var newStaticIndicator = GetPivotHeaderIndicator(StaticHeader, name, NewIndex); if (OldIndex >= 0) { var oldIndicator = GetPivotHeaderIndicator(Header, name, OldIndex); var oldStaticIndicator = GetPivotHeaderIndicator(StaticHeader, name, OldIndex); if (Header != null && newIndicator != null && oldIndicator != null) { TryStartPivotHeaderAnimation(Header, newIndicator, oldIndicator, GetIsScaleEnabled(pivot)); } if (StaticHeader != null && newStaticIndicator != null && oldStaticIndicator != null) { TryStartPivotHeaderAnimation(StaticHeader, newStaticIndicator, oldStaticIndicator, GetIsScaleEnabled(pivot)); } } else { if (newIndicator != null) { newIndicator.Visibility = Visibility.Visible; } if (newStaticIndicator != null) { newStaticIndicator.Visibility = Visibility.Visible; } } } }
public async Task Check_Binding() { var SUT = new Pivot() { HeaderTemplate = PivotHeaderTemplate, ItemTemplate = PivotItemTemplate }; var root = new Grid { DataContext = new MyContext() }; root.Children.Add(SUT); WindowHelper.WindowContent = root; await WindowHelper.WaitForIdle(); var items = (root.DataContext as MyContext)?.Items; SUT.SetBinding(Pivot.ItemsSourceProperty, new Binding { Path = new PropertyPath("Items") }); PivotItem pi = null; await WindowHelper.WaitFor(() => (pi = SUT.ContainerFromItem(items[0]) as PivotItem) != null); var tbs = pi.GetAllChildren(null, false).OfType <TextBlock>().Cast <TextBlock>(); tbs.Should().NotBeNull(); tbs.Should().HaveCount(1); items[0].Content.Should().Be(tbs.ElementAt(0).Text); await WindowHelper.WaitFor(() => (pi = SUT.ContainerFromItem(items[1]) as PivotItem) != null); var tbs2 = pi.GetAllChildren(null, false).OfType <TextBlock>().Cast <TextBlock>(); tbs2.Should().NotBeNull(); tbs2.Should().HaveCount(1); items[1].Content.Should().Be(tbs2.ElementAt(0).Text); }