private void InitializeCompositionObjects() { _headersScrollingProperties = HeadersPanelHost.ScrollProperties(); _contentScrollingProperties = ScrollViewer.ScrollProperties(); _compositor = _headersScrollingProperties.Compositor; _selectedHeaderIndicatorVisual = _selectedHeaderIndicator.Visual(); _selectedHeaderIndicatorHostVisual = _selectedHeaderIndicatorHost.Visual(); }
private void OnLoaded(object sender, RoutedEventArgs e) { Loaded -= OnLoaded; if (Items == null) { return; } SetSelectedHeaderIndicatorVisualBoundaries(); for (var i = 0; i < Items.Count; i++) { var tabItem = ContainerFromIndex(i) as TabItem; if (tabItem == null) { continue; } var header = new TabHeaderItem { DataContext = Items[i], Content = tabItem.Header, HeaderIconStyle = tabItem.HeaderIconStyle, ContentTemplate = HeaderTemplate, IsChecked = i == 0 }; // Have to do this to avoid a bug where RadioButton's GroupName // doesn't function properly after Reloaded. header.Loaded += async(s, args) => { // TODO: There should be a better way to handle this, at system level?? // Put a short delay here to allow the system to calculate the Offset // before we can animate it. await Task.Delay(1000); _isLoaded = true; var h = (TabHeaderItem)s; h.GroupName = "Headers"; UpdateHeaderVisuals(); SyncSelectedHeaderIndicatorVisual(); }; header.Unloaded += (s, args) => { var h = (TabHeaderItem)s; h.GroupName = string.Empty; }; header.Checked += async(s, args) => { UpdateHeaderVisuals(); var h = (TabHeaderItem)s; SelectedIndex = GetHeaderIndex(h); // TODO: We might be able to monitor the scrolling on the HeadersPanelHost and sync the selection visual with the scrolling in real time. // OnHeadersPanelHostDirectManipulationStarted(null, null); await HeadersPanelHost.ScrollToElementAsync(header, false, bringToTopOrLeft : false); SyncSelectedHeaderIndicatorVisual(); }; header.Unchecked += (s, args) => { UpdateHeaderVisuals(); }; header.SizeChanged += (s, args) => { if (!_isLoaded) { return; } UpdateHeaderVisuals(); SyncSelectedHeaderIndicatorVisual(); }; Headers.Add(header); } }