private void OnTabSelected(object s, RoutedEventArgs e) { SelectedItem = (TabSelectorItem)e.OriginalSource; var tabStep = ActualWidth / Tabs.Count; var leftMargin = 0.0; var trace = 0; foreach (var t in Tabs) { if (Equals(t, e.OriginalSource)) { leftMargin = trace * tabStep; } else { t.IsSelected = false; } trace++; } PART_activeindicator.BeginAnimation(WidthProperty, new DoubleAnimation( tabStep, new Duration(TimeSpan.FromMilliseconds(300))) { }); PART_activeindicator.BeginAnimation(MarginProperty, new ThicknessAnimation( new Thickness(leftMargin, 0, 0, 0), new Duration(TimeSpan.FromMilliseconds(300))) { EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }, }); //SelectedItem.DocumentTab.RequestViewTab(); RaiseEvent(new RoutedEventArgs(TabSelectedEvent, e.OriginalSource)); }