WPF measure string display size

        private Size MeasureString()
        {
            var formattedText = new FormattedText(
                this.myabc.Text,
                CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight,
                new Typeface(this.myabc.FontFamily, this.myabc.FontStyle, this.myabc.FontWeight, this.myabc.FontStretch),
                this.myabc.FontSize,
                Brushes.Black,
                new NumberSubstitution(),
                TextFormattingMode.Ideal);
            formattedText.TextAlignment = TextAlignment.Right;
            return new Size(formattedText.Width, formattedText.Height);
        }

おすすめ

転載: blog.csdn.net/xionglifei2014/article/details/125428424