WPF 获取文本像素长度

            var formattedText = new FormattedText(
                Txbox.Text,
                CultureInfo.CurrentUICulture,
                FlowDirection.LeftToRight,
                new Typeface(Txbox.FontFamily, Txbox.FontStyle, Txbox.FontWeight, Txbox.FontStretch),
                Txbox.FontSize,
                Brushes.Black);
            Size size = new Size(formattedText.Width, formattedText.Height);

你可能感兴趣的:(WPF)