我需要根据下面提到的GridComboBoxColumn
的最大长度返回combotext
的宽度,该长度作为ItemsSource
加载。最大的组合文件是"法兰克福a.M.-德国 - 国家"并且WinRT和WPF中的宽度计算如下:
//Calculate width for maximum display text ComboBox items
TextBlock TextBlock = new TextBlock()
{
FontFamily = FontFamily,
Margin = Margin,
FontSize = FontSize,
TextWrapping=TextWrapping.NoWrap
};
//Set the TextBlock display text to combo items text and initialize Height and Width for TextBlock
TextBlock.Text = DisplayText;
var parentBorder = new Border { Child = TextBlock };
TextBlock.MaxHeight = size.Height;
TextBlock.MaxWidth = double.MaxValue;
this.DataGrid.UpdateLayout();
//Measuer the width and Height of parentBorder
parentBorder.Measure(new Size(TextBlock.MaxWidth, TextBlock.MaxHeight));
parentBorder.Child = null;
return parentBorder.DesiredSize.Width;
在WPF中,宽度返回为182.46,在WinRT中,宽度返回为248。但是在WinRT中,列宽适合ComboBox,在WPF中,ComboBox不适合列宽。请告知如何在WPF和WinRT中测量尺寸?