/// <summary> /// 获得当前横向显示的所有的quicklink的长度。 /// </summary> /// <returns></returns> private double GetAllMainItemLength() { double LineWidth = 0; if (MainListBox != null) { foreach (QuickLinksModel LinkModel in MainListBox.Items) { HyperlinkButton linkbt = new HyperlinkButton() { Content = LinkModel.QuickLinkName }; this.LSLayoutRoot.Children.Add(linkbt); linkbt.Measure(new Size(999, 999)); double itemWidth = 0d; //if (linkbt.DesiredSize.Width > 135) //{ // itemWidth = 135; //} //else //{ // itemWidth = linkbt.DesiredSize.Width + 9; //} itemWidth = linkbt.DesiredSize.Width + 16; LineWidth += itemWidth; this.LSLayoutRoot.Children.Remove(linkbt); } } return(LineWidth); }
/// <summary> /// 根据item名称计算link所需要的with /// </summary> /// <param name="ItemName"></param> /// <returns></returns> private double CalculateItemWith(string ItemName) { double itemWidth = 0d; HyperlinkButton linkbt = new HyperlinkButton() { Content = ItemName, Opacity = 0d }; this.LSLayoutRoot.Children.Add(linkbt); linkbt.Measure(new Size(999, 999)); if (linkbt.DesiredSize.Width > 135) { itemWidth = 135; } else { itemWidth = linkbt.DesiredSize.Width + 9; } this.LSLayoutRoot.Children.Remove(linkbt); return(itemWidth); }