WinBT和WPF的TextBlock宽度测量值不同

时间:2015-05-20 04:51:31

标签: c# wpf winrt-xaml

我需要根据下面提到的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中测量尺寸?

0 个答案:

没有答案