/// <summary> /// Called whenever RibbonTabHeaders are measured /// Sums up DesiredSize.Width of each RibbonTabHeader belonging to a ContextualTabGroup and stores it as ContextualTabGroup.TabsDesiredWidth. /// </summary> private void NotifyDesiredWidthChanged() { // Invalidate ContextualTabHeadersPanel RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl; if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost != null) { foreach (RibbonContextualTabGroup tabGroup in groupHeaderItemsControl.InternalItemsHost.Children) { tabGroup.TabsDesiredWidth = 0.0; tabGroup.DesiredExtraPaddingPerTab = 0.0; } } foreach (UIElement element in InternalChildren) { RibbonTabHeader tabHeader = element as RibbonTabHeader; if (tabHeader != null && tabHeader.IsVisible && tabHeader.IsContextualTab) { RibbonContextualTabGroup tabGroup = tabHeader.ContextualTabGroup; if (tabGroup != null) { double previousTabCount = 0; if (!DoubleUtil.IsZero(tabGroup.DesiredExtraPaddingPerTab)) { previousTabCount = (tabGroup.IdealDesiredWidth - tabGroup.TabsDesiredWidth) / tabGroup.DesiredExtraPaddingPerTab; } tabGroup.TabsDesiredWidth += tabHeader.DesiredSize.Width; // compute new average tabGroup.DesiredExtraPaddingPerTab = (tabGroup.IdealDesiredWidth - tabGroup.TabsDesiredWidth) / (previousTabCount + 1); } } } }
/// <summary> /// Property changed called back for IsSelected property /// </summary> private static void OnIsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { RibbonTab ribbonTab = (RibbonTab)sender; if (ribbonTab.IsSelected) { ribbonTab.OnSelected(new RoutedEventArgs(Selector.SelectedEvent, ribbonTab)); } else { ribbonTab.OnUnselected(new RoutedEventArgs(Selector.UnselectedEvent, ribbonTab)); } RibbonTabHeader header = ribbonTab.RibbonTabHeader; if (header != null) { header.CoerceValue(RibbonTabHeader.IsRibbonTabSelectedProperty); } // Raise UI automation events on this RibbonTab if (AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected) || AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)) { RibbonTabAutomationPeer peer = RibbonTabAutomationPeer.CreatePeerForElement(ribbonTab) as RibbonTabAutomationPeer; if (peer != null) { peer.RaiseTabSelectionEvents(); } } }
/// <summary> /// This algorithm calculates the extra Padding that can be assigned to a contextual tab. /// </summary> /// <param name="spaceAvailable"></param> /// <returns></returns> private double CalculateMaxPadding(double spaceAvailable) { UIElementCollection children = InternalChildren; int childCount = children.Count; // Sort DesiredPaddings List <double> desiredPaddings = new List <double>(); double totalDesiredPadding = 0.0; foreach (UIElement element in children) { if (!element.IsVisible) { continue; } RibbonTabHeader tabHeader = element as RibbonTabHeader; if (tabHeader != null && tabHeader.IsContextualTab) { RibbonContextualTabGroup tabGroup = tabHeader.ContextualTabGroup; if (tabGroup != null && DoubleUtil.GreaterThan(tabGroup.DesiredExtraPaddingPerTab, 0.0)) { // ContextualTabGroup requires this much more width to reach its ideal DesiredSize. double desiredPaddingPerTabHeader = tabGroup.DesiredExtraPaddingPerTab; desiredPaddings.Add(desiredPaddingPerTabHeader); totalDesiredPadding += desiredPaddingPerTabHeader; } } } int sizeCount = desiredPaddings.Count; if (sizeCount == 0) { return(0.0); } desiredPaddings.Sort(); double delta = totalDesiredPadding - spaceAvailable; if (DoubleUtil.LessThanOrClose(delta, 0.0)) { return(desiredPaddings[sizeCount - 1]); } // Clip the TabHeader requesting most extra Padding double maxDesiredPadding = desiredPaddings[sizeCount - 1] - delta; for (int i = 1; i < sizeCount; i++) { double currentDesiredPadding = desiredPaddings[sizeCount - 1 - i]; if (DoubleUtil.GreaterThanOrClose(maxDesiredPadding, currentDesiredPadding)) { break; } // Include next element and calculate new average maxDesiredPadding = ((maxDesiredPadding * i) + currentDesiredPadding) / (i + 1); } return(maxDesiredPadding); }
/// <summary> /// Arranges contextual tab headers /// </summary> private void ArrangeContextualTabHeaders(Size arrangeSize, Ribbon ribbon, Dictionary <object, List <RibbonTabHeaderAndIndex> > contextualTabHeaders, ref int displayIndex, ref double childX) { if (ribbon != null) { RibbonContextualTabGroupItemsControl groupHeaderItemsControl = ribbon.ContextualTabGroupItemsControl; if (groupHeaderItemsControl != null) { if (groupHeaderItemsControl.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) { int groupHeaderCount = groupHeaderItemsControl.Items.Count; for (int i = 0; i < groupHeaderCount; i++) { RibbonContextualTabGroup groupHeader = groupHeaderItemsControl.ItemContainerGenerator.ContainerFromIndex(i) as RibbonContextualTabGroup; if (groupHeader != null) { object contextualTabGroupHeader = groupHeader.Header; if (contextualTabGroupHeader != null && contextualTabHeaders.ContainsKey(contextualTabGroupHeader)) { foreach (RibbonTabHeaderAndIndex headerAndIndex in contextualTabHeaders[contextualTabGroupHeader]) { RibbonTabHeader child = headerAndIndex.RibbonTabHeader; Debug.Assert(child != null); child.InvalidateVisual(); child.Arrange(new Rect(childX - HorizontalOffset, arrangeSize.Height - child.DesiredSize.Height, child.DesiredSize.Width, child.DesiredSize.Height)); childX += child.DesiredSize.Width; ribbon.TabDisplayIndexToIndexMap[displayIndex] = headerAndIndex.Index; ribbon.TabIndexToDisplayIndexMap[headerAndIndex.Index] = displayIndex; displayIndex++; } contextualTabHeaders.Remove(contextualTabGroupHeader); } } } RibbonContextualTabGroupsPanel contextualTabGroupsPanel = groupHeaderItemsControl.InternalItemsHost as RibbonContextualTabGroupsPanel; if (contextualTabGroupsPanel != null) { contextualTabGroupsPanel.WaitingForMeasure = false; } } else { // Tell the ContextualTabGroupsPanel that we are waiting on its Measure. RibbonContextualTabGroupsPanel contextualTabGroupsPanel = groupHeaderItemsControl.InternalItemsHost as RibbonContextualTabGroupsPanel; if (contextualTabGroupsPanel != null) { contextualTabGroupsPanel.WaitingForMeasure = true; } } } } }
/// <summary> /// Measures all the children with original constraints. /// </summary> private Size InitialMeasure(Size constraint, out double totalDefaultPaddingAllTabHeaders, out double totalDefaultPaddingRegularTabHeaders, out double totalDesiredWidthRegularTabHeaders, out int countRegularTabs, out int countVisibleTabs) { totalDefaultPaddingAllTabHeaders = 0; totalDefaultPaddingRegularTabHeaders = 0; totalDesiredWidthRegularTabHeaders = 0; countRegularTabs = 0; countVisibleTabs = 0; UIElementCollection children = InternalChildren; Size desiredSize = new Size(); int countAllTabs = children.Count; for (int i = 0; i < countAllTabs; i++) { RibbonTabHeader ribbonTabHeader = children[i] as RibbonTabHeader; if (ribbonTabHeader != null) { if (!ribbonTabHeader.IsVisible) { continue; } ribbonTabHeader.Padding = ribbonTabHeader.DefaultPadding; // Always do first meassure with default padding double tabHeaderPadding = ribbonTabHeader.DefaultPadding.Left + ribbonTabHeader.DefaultPadding.Right; totalDefaultPaddingAllTabHeaders += tabHeaderPadding; bool isContextualTab = ribbonTabHeader.IsContextualTab; ribbonTabHeader.Measure(constraint); desiredSize.Width += ribbonTabHeader.DesiredSize.Width; desiredSize.Height = Math.Max(desiredSize.Height, ribbonTabHeader.DesiredSize.Height); if (!isContextualTab) { totalDefaultPaddingRegularTabHeaders += tabHeaderPadding; totalDesiredWidthRegularTabHeaders += ribbonTabHeader.DesiredSize.Width; countRegularTabs++; } } else { UIElement child = children[i]; if (!child.IsVisible) { continue; } child.Measure(constraint); desiredSize.Width += child.DesiredSize.Width; desiredSize.Height = Math.Max(desiredSize.Height, child.DesiredSize.Height); totalDesiredWidthRegularTabHeaders += child.DesiredSize.Width; countRegularTabs++; } countVisibleTabs++; } return(desiredSize); }
// This method determine how much tabs will be clipped by caluclating the maximum tab width // clipWidth parameter is the amount the needs to be removed from tabs // Algorithm steps: // 1. Sort all tabs sizes // 2. maxTabWidth = max tab size - clipWidth // 3. if there is an element bigger that maxTabWidth - include this element and calulate new average // 4. Return maxTabWidth coerced with some min width private double CalculateMaxTabHeaderWidth(double clipWidth, bool forContextualTabs) { // If clipping is not necessary - return Max double if (DoubleUtil.LessThanOrClose(clipWidth, 0)) { return(Double.MaxValue); } UIElementCollection children = InternalChildren; int childCount = children.Count; // Sort element sizes without the padding List <double> elementSizes = new List <double>(); foreach (UIElement element in children) { if (!element.IsVisible) { continue; } double elementSize = element.DesiredSize.Width; RibbonTabHeader tabHeader = element as RibbonTabHeader; if (tabHeader != null) { if (tabHeader.IsContextualTab != forContextualTabs) { continue; } elementSize = elementSize - tabHeader.DefaultPadding.Left - tabHeader.DefaultPadding.Right; } elementSizes.Add(elementSize); } int sizeCount = elementSizes.Count; if (sizeCount == 0) { return(_tabHeaderMinWidth); } elementSizes.Sort(); // Clip the max element double maxTabHeaderWidth = elementSizes[sizeCount - 1] - clipWidth; for (int i = 1; i < sizeCount; i++) { double currentWidth = elementSizes[sizeCount - 1 - i]; if (DoubleUtil.GreaterThanOrClose(maxTabHeaderWidth, currentWidth)) { break; } // Include next element and calculate new average maxTabHeaderWidth = ((maxTabHeaderWidth * i) + currentWidth) / (i + 1); } return(Math.Max(_tabHeaderMinWidth, maxTabHeaderWidth)); }
private static void OnKeyTipChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonTab tab = (RibbonTab)d; RibbonTabHeader tabHeader = tab.RibbonTabHeader; if (tabHeader != null) { tabHeader.CoerceValue(KeyTipService.KeyTipProperty); } }
/// <summary> /// Prepares an item container before its use. /// </summary> protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { base.PrepareContainerForItemOverride(element, item); RibbonTabHeader header = element as RibbonTabHeader; if (header != null) { header.PrepareRibbonTabHeader(); } }
/// <summary> /// Property changed callback for IsEnabled property. /// <summary> private static void OnIsEnabledChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { RibbonTab ribbonTab = (RibbonTab)sender; RibbonTabHeader header = ribbonTab.RibbonTabHeader; if (header != null) { header.CoerceValue(RibbonTabHeader.IsEnabledProperty); } }
/// <summary> /// Coercion callback for IsEnabled property /// </summary> /// <param name="d"></param> /// <param name="baseValue"></param> /// <returns></returns> private static object OnCoerceIsEnabled(DependencyObject d, object baseValue) { RibbonTabHeader header = (RibbonTabHeader)d; RibbonTab tab = header.RibbonTab; if (tab != null) { return(tab.IsEnabled); } return(baseValue); }
private RibbonTabHeaderAutomationPeer GetWrapperPeer() { RibbonTabHeaderAutomationPeer wrapperPeer = null; RibbonTabHeader wrapper = GetWrapper(); if (wrapper != null) { wrapperPeer = UIElementAutomationPeer.CreatePeerForElement(wrapper) as RibbonTabHeaderAutomationPeer; } return(wrapperPeer); }
private static object CoerceVisibility(DependencyObject d, object baseValue) { RibbonTabHeader header = (RibbonTabHeader)d; RibbonTab tab = header.RibbonTab; if (tab != null) { return(tab.Visibility); } return(baseValue); }
private static object CoerceKeyTip(DependencyObject d, object baseValue) { RibbonTabHeader tabHeader = (RibbonTabHeader)d; RibbonTab tab = tabHeader.RibbonTab; if (tab != null) { return(tab.KeyTip); } return(baseValue); }
private static object CoerceStringFormat(DependencyObject d, object baseValue) { RibbonTabHeader tabHeader = (RibbonTabHeader)d; return(PropertyHelper.GetCoercedTransferPropertyValue( d, baseValue, ContentStringFormatProperty, tabHeader.RibbonTab, RibbonTab.HeaderStringFormatProperty)); }
private static object CoerceContentTemplateSelector(DependencyObject d, object baseValue) { RibbonTabHeader tabHeader = (RibbonTabHeader)d; return(PropertyHelper.GetCoercedTransferPropertyValue( d, baseValue, ContentTemplateSelectorProperty, tabHeader.RibbonTab, RibbonTab.HeaderTemplateSelectorProperty)); }
private static object CoerceIsContextualTab(DependencyObject d, object baseValue) { RibbonTabHeader tabHeader = (RibbonTabHeader)d; RibbonTab tab = tabHeader.RibbonTab; if (tab != null) { return(tab.ContextualTabGroupHeader != null); } return(baseValue); }
private static void OnNotifyHeaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonTab tab = (RibbonTab)d; tab.NotifyPropertyChanged(e); RibbonTabHeader tabHeader = tab.RibbonTabHeader; if (tabHeader != null) { tabHeader.NotifyPropertyChanged(e); } }
private static object CoerceStyle(DependencyObject d, object baseValue) { RibbonTabHeader tabHeader = (RibbonTabHeader)d; return(PropertyHelper.GetCoercedTransferPropertyValue( d, baseValue, StyleProperty, tabHeader.RibbonTab, RibbonTab.HeaderStyleProperty, tabHeader.Ribbon, Ribbon.TabHeaderStyleProperty)); }
/// <summary> /// Set show tooltips depending on whether the tab header is clipped or not. /// </summary> /// <param name="showRegularTabHeaderToolTips"></param> /// <param name="showContextualTabHeaderToolTips"></param> private void UpdateToolTips(bool showRegularTabHeaderToolTips, bool showContextualTabHeaderToolTips) { UIElementCollection children = InternalChildren; int countAllTabs = children.Count; for (int i = 0; i < countAllTabs; i++) { RibbonTabHeader tabHeader = children[i] as RibbonTabHeader; if (tabHeader != null) { tabHeader.ShowLabelToolTip = tabHeader.IsContextualTab ? showContextualTabHeaderToolTips : showRegularTabHeaderToolTips; } } }
internal void PrepareRibbonTab() { if (ContextualTabGroupHeader != null && Ribbon.ContextualTabGroupItemsControl != null) { ContextualTabGroup = Ribbon.ContextualTabGroupItemsControl.FindHeader(ContextualTabGroupHeader); } CoerceValue(VisibilityProperty); RibbonTabHeader tabHeader = RibbonTabHeader; if (tabHeader != null) { tabHeader.InitializeTransferProperties(); } }
/// <summary> /// Arranges regular tab headers and builds a map of /// RibbonTab.ContextualTabGroupHeader to list of RibbonTabHeaders /// </summary> /// <param name="arrangeSize"></param> /// <param name="ribbon"></param> /// <param name="contextualTabHeaders"></param> /// <param name="displayIndex"></param> /// <param name="childX"></param> private void ArrangeRegularTabHeaders(Size arrangeSize, Ribbon ribbon, Dictionary <object, List <RibbonTabHeaderAndIndex> > contextualTabHeaders, ref int displayIndex, ref double childX) { UIElementCollection children = InternalChildren; int childCount = children.Count; for (int i = 0; i < childCount; i++) { UIElement child = children[i]; if (!child.IsVisible) { continue; } RibbonTabHeader tabHeader = child as RibbonTabHeader; if (tabHeader != null) { RibbonTab tab = tabHeader.RibbonTab; if (tab != null && tab.IsContextualTab) { object contextualTabGroupHeader = tab.ContextualTabGroupHeader; if (!contextualTabHeaders.ContainsKey(contextualTabGroupHeader)) { contextualTabHeaders[contextualTabGroupHeader] = new List <RibbonTabHeaderAndIndex>(); } contextualTabHeaders[contextualTabGroupHeader].Add(new RibbonTabHeaderAndIndex() { RibbonTabHeader = tabHeader, Index = i }); continue; } } child.InvalidateVisual(); child.Arrange(new Rect(childX - HorizontalOffset, arrangeSize.Height - child.DesiredSize.Height, child.DesiredSize.Width, child.DesiredSize.Height)); childX += child.DesiredSize.Width; if (ribbon != null) { ribbon.TabDisplayIndexToIndexMap[displayIndex] = i; ribbon.TabIndexToDisplayIndexMap[i] = displayIndex; displayIndex++; } } }
/// <summary> /// Measures all the children with final constraints /// </summary> private Size FinalMeasure(Size constraint, double reducePaddingContextualTabHeader, double reducePaddingRegularTabHeader, double maxContextualTabHeaderWidth, double maxRegularTabHeaderWidth) { Size desiredSize = new Size(); UIElementCollection children = InternalChildren; int countAllTabs = children.Count; for (int i = 0; i < countAllTabs; i++) { RibbonTabHeader ribbonTabHeader = children[i] as RibbonTabHeader; if (ribbonTabHeader != null) { if (!ribbonTabHeader.IsVisible) { continue; } bool isContextualTab = ribbonTabHeader.IsContextualTab; double leftPadding = Math.Max(0, ribbonTabHeader.DefaultPadding.Left - (isContextualTab ? reducePaddingContextualTabHeader : reducePaddingRegularTabHeader)); double rightPadding = Math.Max(0, ribbonTabHeader.DefaultPadding.Right - (isContextualTab ? reducePaddingContextualTabHeader : reducePaddingRegularTabHeader)); ribbonTabHeader.Padding = new Thickness(leftPadding, ribbonTabHeader.DefaultPadding.Top, rightPadding, ribbonTabHeader.DefaultPadding.Bottom); ribbonTabHeader.Measure(new Size(isContextualTab ? maxContextualTabHeaderWidth : maxRegularTabHeaderWidth, constraint.Height)); desiredSize.Width += ribbonTabHeader.DesiredSize.Width; desiredSize.Height = Math.Max(desiredSize.Height, ribbonTabHeader.DesiredSize.Height); } else { UIElement child = children[i]; if (!child.IsVisible) { continue; } child.Measure(new Size(maxRegularTabHeaderWidth, constraint.Height)); desiredSize.Width += child.DesiredSize.Width; desiredSize.Height = Math.Max(desiredSize.Height, child.DesiredSize.Height); } } return(desiredSize); }
/// <summary> /// Calculates the x-position at which the given ContextualTabGroup should be placed on the title panel. /// </summary> /// <param name="group">The RibbonContextualTabGroup to position.</param> /// <returns>The x-offset at which the ContextualTabGroup should be positioned.</returns> private double CalculateContextualTabGroupStartX(RibbonContextualTabGroup groupHeader) { double result = 0.0; // A visible CTG can have some of its tabs Collapsed. // We should start from the first visible Tab in this CTG. RibbonTab firstTab = groupHeader.FirstVisibleTab; if (firstTab != null && firstTab.RibbonTabHeader != null && Ribbon != null) { RibbonTabHeader tabHeader = firstTab.RibbonTabHeader; GeneralTransform transformRibbonTabToRibbon = tabHeader.TransformToAncestor(Ribbon); GeneralTransform transformRibbonToRibbonTitlePanel = Ribbon.TransformToDescendant(this); Point point = new Point(); point = transformRibbonTabToRibbon.Transform(point); point = transformRibbonToRibbonTitlePanel.Transform(point); result = point.X - tabHeader.Margin.Left; // Reduce RibbonTab Margin } return(result); }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (!e.Handled) { DependencyObject focusedElement = Keyboard.FocusedElement as DependencyObject; RibbonTabHeader tabHeader = RibbonTabHeader; if (e.Key == Key.Up && focusedElement != null && tabHeader != null) { // On arrow up key press if the focus goes out of the tab, // then force it to move to the corresponding TabHeader. DependencyObject upObj = RibbonHelper.PredictFocus(focusedElement, FocusNavigationDirection.Up); if (!RibbonHelper.IsAncestorOf(this, upObj)) { if (tabHeader.Focus()) { e.Handled = true; } } } } }
/// <summary> /// Dựng menu ribbon của hệ thống theo user đăng nhập /// </summary> /// <param name="rbMenu">Control Menu ribbon được tham chiếu, xử lý rồi trả về</param> public void KhoiTaoMenu(ref Ribbon rbMenu) { try { string toolTip; ChucNangDto[] ChucNanglst = ClientInformation.ListChucNang.Select(e => e).ToArray(); IQueryable <ChucNangDto> sItem; string pathFolderImages = ApplicationConstant.defaultImageSource; // Lấy danh sách menu theo tên đăng nhập và mã đơn vị var sTab = ChucNanglst.Where(e => e.IDChucNangCha == 0).OrderBy(e => e.STT).ToList(); foreach (var Tab in sTab) { if (Tab.ThuocTinh.SplitByDelimiter("#")[2] == "RibbonApplicationMenu") { // Application menu RibbonApplicationMenu ram = new RibbonApplicationMenu(); ram.Label = Utilities.Common.LLanguage.SearchResourceByKey(Tab.TieuDe); if (!Tab.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Tab.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Tab.TieuDe; } ram.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); ram.KeyTip = Tab.ThuocTinh.SplitByDelimiter("#")[3]; ram.Uid = Tab.IDChucNang.ToString(); if (!Tab.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Tab.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Tab.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); // RibbonMenuItem icon always small ram.SmallImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Tab.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); ram.SmallImageSource = bmp; } } catch { } } var sMenu = ChucNanglst.Where(e => e.IDChucNangCha == Tab.IDChucNang).OrderBy(e => e.STT).AsQueryable(); foreach (var Menu in sMenu) { switch (Menu.ThuocTinh.SplitByDelimiter("#")[2]) { case "RibbonApplicationSplitMenuItem": if (Menu.Quyen == 0) { goto case "RibbonApplicationMenuItem"; } var rasmi = new RibbonApplicationSplitMenuItem(); rasmi.Name = "ID" + Menu.IDChucNang.ToString(); rasmi.Header = Utilities.Common.LLanguage.SearchResourceByKey(Menu.TieuDe); if (!Menu.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Menu.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Menu.TieuDe; } rasmi.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); rasmi.KeyTip = Menu.ThuocTinh.SplitByDelimiter("#")[3]; rasmi.Uid = Menu.IDChucNang.ToString(); if (!Menu.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); // RibbonApplicationSplitMenuItem icon always large rasmi.ImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); // QuickAccessToolBar icon always small rasmi.QuickAccessToolBarImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); rasmi.ImageSource = bmp; rasmi.QuickAccessToolBarImageSource = bmp; } } catch { } } rasmi.Tag = Menu; //rasmi.IsEnabled = Menu.Quyen > 0; // Items sItem = ChucNanglst.Where(e => e.IDChucNangCha == Menu.IDChucNang).OrderBy(e => e.STT).AsQueryable(); foreach (var Item in sItem) { var item = new RibbonApplicationMenuItem(); item.Name = "ID" + Item.IDChucNang.ToString(); item.Header = Utilities.Common.LLanguage.SearchResourceByKey(Item.TieuDe); if (!Item.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Item.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Item.TieuDe; } item.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); item.KeyTip = Item.ThuocTinh.SplitByDelimiter("#")[3]; item.Uid = Item.IDChucNang.ToString(); if (!Item.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Item.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); // RibbonApplicationMenuItem icon always large item.ImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); // QuickAccessToolBar icon always small item.QuickAccessToolBarImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); item.ImageSource = bmp; item.QuickAccessToolBarImageSource = bmp; } } catch { } } item.Tag = Item; item.IsEnabled = Item.Quyen > 0; rasmi.Items.Add(item); } ram.Items.Add(rasmi); break; case "RibbonApplicationMenuItem": var rami = new RibbonApplicationMenuItem(); rami.Name = "ID" + Menu.IDChucNang.ToString(); rami.Header = Utilities.Common.LLanguage.SearchResourceByKey(Menu.TieuDe); if (!Menu.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Menu.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Menu.TieuDe; } rami.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); rami.KeyTip = Menu.ThuocTinh.SplitByDelimiter("#")[3]; rami.Uid = Menu.IDChucNang.ToString(); if (!Menu.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); // RibbonApplicationMenuItem icon always large rami.ImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); // QuickAccessToolBar icon always small rami.QuickAccessToolBarImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); rami.ImageSource = bmp; rami.QuickAccessToolBarImageSource = bmp; } } catch { } } if (!Menu.ChucNang.IsNullOrEmptyOrSpace()) { rami.Tag = Menu; } //rami.IsEnabled = Menu.Quyen > 0; // Items sItem = ChucNanglst.Where(e => e.IDChucNangCha == Menu.IDChucNang).OrderBy(e => e.STT).AsQueryable(); foreach (var Item in sItem) { var item = new RibbonApplicationMenuItem(); item.Name = "ID" + Item.IDChucNang.ToString(); item.Header = Utilities.Common.LLanguage.SearchResourceByKey(Item.TieuDe); if (!Item.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Item.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Item.TieuDe; } item.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); item.KeyTip = Item.ThuocTinh.SplitByDelimiter("#")[3]; item.Uid = Item.IDChucNang.ToString(); if (!Item.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Item.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); // RibbonApplicationMenuItem icon always large item.ImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); // QuickAccessToolBar icon always small item.QuickAccessToolBarImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); item.ImageSource = bmp; item.QuickAccessToolBarImageSource = bmp; } } catch { } } item.Tag = Item; item.IsEnabled = Item.Quyen > 0; rami.Items.Add(item); } ram.Items.Add(rami); break; default: Grid grid; if (ram.FooterPaneContent.IsNullOrEmpty()) { grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition()); ColumnDefinition cd = new ColumnDefinition(); cd.Width = GridLength.Auto; grid.ColumnDefinitions.Add(cd); ram.FooterPaneContent = grid; } else { grid = (Grid)(ram.FooterPaneContent); } var rb = new RibbonButton(); rb.Name = "ID" + Menu.IDChucNang.ToString(); rb.Label = Utilities.Common.LLanguage.SearchResourceByKey(Menu.TieuDe); if (!Menu.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Menu.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Menu.TieuDe; } rb.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); rb.KeyTip = Menu.ThuocTinh.SplitByDelimiter("#")[3]; rb.Uid = Menu.IDChucNang.ToString(); if (!Menu.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); rb.LargeImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); rb.SmallImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Large") { rb.LargeImageSource = bmp; } else { rb.SmallImageSource = bmp; } } } catch { } } rb.Tag = Menu; rb.IsEnabled = Menu.Quyen > 0; grid.Children.Add(rb); Grid.SetColumn(rb, 1); break; } } rbMenu.ApplicationMenu = ram; } else { // Tabs RibbonTab tab = new RibbonTab(); Type rthType = new RibbonTabHeader().GetType(); tab.Header = Utilities.Common.LLanguage.SearchResourceByKey(Tab.TieuDe); if (!Tab.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Tab.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Tab.TieuDe; } tab.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); tab.HeaderStyle = new Style(rthType); tab.HeaderStyle.Setters.Add(new Setter(RibbonWindow.ToolTipProperty, tab.ToolTip)); tab.IsEnabled = Tab.Quyen > 0; tab.Uid = Tab.IDChucNang.ToString(); // Groups var sGroup = ChucNanglst.Where(e => e.IDChucNangCha == Tab.IDChucNang).OrderBy(e => e.STT).AsQueryable(); foreach (var Group in sGroup) { RibbonGroup group = new RibbonGroup(); group.Header = Utilities.Common.LLanguage.SearchResourceByKey(Group.TieuDe); group.IsEnabled = Group.Quyen > 0; // Buttons var sMenu = ChucNanglst.Where(e => e.IDChucNangCha == Group.IDChucNang).OrderBy(e => e.STT).AsQueryable(); foreach (var Menu in sMenu) { switch (Menu.ThuocTinh.SplitByDelimiter("#")[2]) { case "RibbonSplitButton": if (Menu.Quyen == 0) { goto case "RibbonMenuButton"; } var rsb = new RibbonSplitButton(); rsb.Name = "ID" + Menu.IDChucNang.ToString(); rsb.Label = Utilities.Common.LLanguage.SearchResourceByKey(Menu.TieuDe); if (!Menu.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Menu.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Menu.TieuDe; } rsb.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); rsb.KeyTip = Menu.ThuocTinh.SplitByDelimiter("#")[3]; rsb.Uid = Menu.IDChucNang.ToString(); if (!Menu.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); rsb.LargeImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); rsb.SmallImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Large") { rsb.LargeImageSource = bmp; } else { rsb.SmallImageSource = bmp; } } } catch { } } rsb.Tag = Menu; //rsb.IsEnabled = Menu.Quyen > 0; // Items sItem = ChucNanglst.Where(e => e.IDChucNangCha == Menu.IDChucNang).OrderBy(e => e.STT).AsQueryable(); foreach (var Item in sItem) { var item = new RibbonMenuItem(); item.Name = "ID" + Item.IDChucNang.ToString(); item.Header = Utilities.Common.LLanguage.SearchResourceByKey(Item.TieuDe); if (!Item.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Item.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Item.TieuDe; } item.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); item.KeyTip = Item.ThuocTinh.SplitByDelimiter("#")[3]; item.Uid = Item.IDChucNang.ToString(); if (!Item.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Item.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); // RibbonMenuItem icon always small item.ImageSource = bmp; // QuickAccessToolBar icon always small item.QuickAccessToolBarImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); item.ImageSource = bmp; item.QuickAccessToolBarImageSource = bmp; } } catch { } } item.Tag = Item; item.IsEnabled = Item.Quyen > 0; rsb.Items.Add(item); } group.Items.Add(rsb); break; case "RibbonMenuButton": var rmb = new RibbonMenuButton(); rmb.Name = "ID" + Menu.IDChucNang.ToString(); rmb.Label = Utilities.Common.LLanguage.SearchResourceByKey(Menu.TieuDe); if (!Menu.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Menu.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Menu.TieuDe; } rmb.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); rmb.KeyTip = Menu.ThuocTinh.SplitByDelimiter("#")[3]; rmb.Uid = Menu.IDChucNang.ToString(); if (!Menu.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); rmb.LargeImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); rmb.SmallImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Large") { rmb.LargeImageSource = bmp; } else { rmb.SmallImageSource = bmp; } } } catch { } } //rmb.IsEnabled = Menu.Quyen > 0; // Items sItem = ChucNanglst.Where(e => e.IDChucNangCha == Menu.IDChucNang).OrderBy(e => e.STT).AsQueryable(); foreach (var Item in sItem) { var item = new RibbonMenuItem(); item.Name = "ID" + Item.IDChucNang.ToString(); item.Header = Utilities.Common.LLanguage.SearchResourceByKey(Item.TieuDe); if (!Item.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Item.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Item.TieuDe; } item.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); item.KeyTip = Item.ThuocTinh.SplitByDelimiter("#")[3]; item.Uid = Item.IDChucNang.ToString(); if (!Item.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Item.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); // RibbonMenuItem icon always small item.ImageSource = bmp; // QuickAccessToolBar icon always small item.QuickAccessToolBarImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Item.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); item.ImageSource = bmp; item.QuickAccessToolBarImageSource = bmp; } } catch { } } item.Tag = Item; item.IsEnabled = Item.Quyen > 0; rmb.Items.Add(item); } group.Items.Add(rmb); break; default: var rb = new RibbonButton(); rb.Name = "ID" + Menu.IDChucNang.ToString(); rb.Label = Utilities.Common.LLanguage.SearchResourceByKey(Menu.TieuDe); if (!Menu.ThuocTinh.SplitByDelimiter("#")[0].IsNullOrEmptyOrSpace()) { toolTip = Menu.ThuocTinh.SplitByDelimiter("#")[0]; } else { toolTip = Menu.TieuDe; } rb.ToolTip = Utilities.Common.LLanguage.SearchResourceByKey(toolTip); rb.KeyTip = Menu.ThuocTinh.SplitByDelimiter("#")[3]; rb.Uid = Menu.IDChucNang.ToString(); if (!Menu.BieuTuong.IsNullOrEmptyOrSpace()) { try { BitmapImage bmp = new BitmapImage(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Both") { bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[0], UriKind.RelativeOrAbsolute); bmp.EndInit(); rb.LargeImageSource = bmp; bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong.SplitByDelimiter("#")[1], UriKind.RelativeOrAbsolute); bmp.EndInit(); rb.SmallImageSource = bmp; } else { // Lagre or Small bmp.BeginInit(); bmp.UriSource = new Uri(pathFolderImages + Menu.BieuTuong, UriKind.RelativeOrAbsolute); bmp.EndInit(); if (Menu.ThuocTinh.SplitByDelimiter("#")[1] == "Large") { rb.LargeImageSource = bmp; } else { rb.SmallImageSource = bmp; } } } catch (Exception ex) { LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); } } rb.Tag = Menu; rb.IsEnabled = Menu.Quyen > 0; group.Items.Add(rb); break; } } tab.Items.Add(group); } rbMenu.Items.Add(tab); } } } catch (Exception ex) { // Ghi log Exception LLogging.WriteLog(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString(), LLogging.LogType.ERR, ex); } }
public RibbonTabHeaderAutomationPeer(RibbonTabHeader owner) : base(owner) { }
/// <summary> /// Measure /// </summary> protected override Size MeasureOverride(Size availableSize) { // Note: The logic below assumes that the TabHeaders belonging to inactive // ContextualTabGroups have their IsVisible set to false. //_separatorOpacity = 0.0; Size desiredSize = new Size(); UIElementCollection children = InternalChildren; if (children.Count == 0) { return(desiredSize); } Size childConstraint = new Size(double.PositiveInfinity, availableSize.Height); int countRegularTabs = 0; double totalDefaultPaddingAllTabHeaders = 0; double totalDefaultPaddingRegularTabHeaders = 0; double totalDesiredWidthRegularTabHeaders = 0; bool showRegularTabHeaderToolTips = false; bool showContextualTabHeaderToolTips = false; int countVisibleTabs = 0; // Measure all TabHeaders to fit their content // desiredSize should hold the total size required to fit all TabHeaders desiredSize = InitialMeasure(childConstraint, out totalDefaultPaddingAllTabHeaders, out totalDefaultPaddingRegularTabHeaders, out totalDesiredWidthRegularTabHeaders, out countRegularTabs, out countVisibleTabs); int countContextualTabs = countVisibleTabs - countRegularTabs; SpaceAvailable = 0.0; double overflowWidth = desiredSize.Width - availableSize.Width; // Total overflow width if (DoubleUtil.GreaterThan(overflowWidth, 0)) { // Calculate max tab width if tab clipping is necessary double totalClipWidthRegularTabHeaders = 0; // How much pixels we need to clip regular tabs double totalClipWidthContextualTabHeaders = 0; // How much pixels we need to clip contextual tabs if (DoubleUtil.GreaterThan(overflowWidth, totalDefaultPaddingAllTabHeaders)) // Clipping is necessary - all tabs padding will we 0 { showRegularTabHeaderToolTips = true; totalClipWidthRegularTabHeaders = overflowWidth - totalDefaultPaddingAllTabHeaders; // Try to use the whole totalClipAmount in the regular tabs } double maxRegularTabHeaderWidth = CalculateMaxTabHeaderWidth(totalClipWidthRegularTabHeaders, false); if (DoubleUtil.AreClose(maxRegularTabHeaderWidth, _tabHeaderMinWidth)) // Regular tabs are clipped to the min size - need to clip contextual tabs { showContextualTabHeaderToolTips = true; double totalClipAmount = overflowWidth - totalDefaultPaddingAllTabHeaders; double usedClipAmount = totalDesiredWidthRegularTabHeaders - totalDefaultPaddingRegularTabHeaders - (_tabHeaderMinWidth * countRegularTabs); totalClipWidthContextualTabHeaders = totalClipAmount - usedClipAmount; // Remaining clipping amount } double maxContextualTabHeaderWidth = CalculateMaxTabHeaderWidth(totalClipWidthContextualTabHeaders, true); double reducePaddingRegularTabHeader = 0; double reducePaddingContextualTabHeader = 0; if (DoubleUtil.GreaterThanOrClose(totalDefaultPaddingRegularTabHeaders, overflowWidth)) { reducePaddingRegularTabHeader = (0.5 * overflowWidth) / countRegularTabs; //_separatorOpacity = Math.Max(0.0, reducePaddingRegularTabHeader * 0.2); } else { //_separatorOpacity = 1.0; reducePaddingRegularTabHeader = double.PositiveInfinity; // If countContextualTabs==0 then reducePaddingContextualTab will become Infinity reducePaddingContextualTabHeader = (0.5 * (overflowWidth - totalDefaultPaddingRegularTabHeaders)) / (countVisibleTabs - countRegularTabs); } desiredSize = FinalMeasure(childConstraint, reducePaddingContextualTabHeader, reducePaddingRegularTabHeader, maxContextualTabHeaderWidth, maxRegularTabHeaderWidth); } else if (countContextualTabs > 0) { // After assigning DefaultPadding, we are left with extra space. // If contextual tabs need that extra space, assign them more padding. NotifyDesiredWidthChanged(); double spaceAvailable = availableSize.Width - desiredSize.Width; double availableExtraWidthPerTab = CalculateMaxPadding(spaceAvailable); foreach (UIElement child in InternalChildren) { RibbonTabHeader ribbonTabHeader = child as RibbonTabHeader; if (ribbonTabHeader != null && ribbonTabHeader.IsVisible && ribbonTabHeader.IsContextualTab) { RibbonContextualTabGroup ctg = ribbonTabHeader.ContextualTabGroup; if (ctg != null && DoubleUtil.GreaterThan(ctg.DesiredExtraPaddingPerTab, 0.0)) { double desiredExtraPaddingPerTab = ctg.DesiredExtraPaddingPerTab; double availableExtraWidth = Math.Min(desiredExtraPaddingPerTab, availableExtraWidthPerTab); Thickness newPadding = ribbonTabHeader.Padding; newPadding.Left += availableExtraWidth * 0.5; newPadding.Right += availableExtraWidth * 0.5; ribbonTabHeader.Padding = newPadding; // Remeasure with added padding desiredSize.Width -= ribbonTabHeader.DesiredSize.Width; ribbonTabHeader.Measure(new Size(Double.MaxValue, childConstraint.Height)); desiredSize.Width += ribbonTabHeader.DesiredSize.Width; } } } } // If the difference between desiredWidth and constraintWidth is less // than 1e-10 then assume that both are same. This avoids unnecessary // inequalities in extent and viewport resulting in spontaneous // flickering of scroll button. if (Math.Abs(desiredSize.Width - availableSize.Width) < _desiredWidthEpsilon) { desiredSize.Width = availableSize.Width; } SpaceAvailable = availableSize.Width - desiredSize.Width; // Update ContextualTabGroup.TabsDesiredWidth NotifyDesiredWidthChanged(); // Update whether tooltips should be shown. UpdateToolTips(showRegularTabHeaderToolTips, showContextualTabHeaderToolTips); VerifyScrollData(availableSize.Width, desiredSize.Width); // Invalidate ContextualTabHeadersPanel if (Ribbon != null) { RibbonContextualTabGroupItemsControl groupHeaderItemsControl = Ribbon.ContextualTabGroupItemsControl; if (groupHeaderItemsControl != null && groupHeaderItemsControl.InternalItemsHost != null) { groupHeaderItemsControl.InternalItemsHost.InvalidateMeasure(); } } return(desiredSize); }