本文介绍了FormattedText.FormttedText已过时.使用PixelsPerDip替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将标签填充到水平滑块,并且我成功地使用了从TickBar
派生的类,并将Text传递给FormattedText构造函数,成功做到了这一点.但是现在,当我使用相同的代码并将其粘贴到使用.NET Framework 4.6.2版的Visual Studio中时,它说:
I am trying to populate labels to a horizontal slider and I was successfully able to do it using a class that derives from TickBar
by passing the Text to FormattedText constructor. But now when I take the same code and paste it in Visual Studio that uses .NET Framework version 4.6.2, it says:
FormattedText.FormttedText已过时.使用PixelsPerDip替代.
FormattedText.FormttedText is obsolete. Use the PixelsPerDip override.
我指的是
但是在当前情况下,我该如何使用它.请帮忙.
But how can I use that in this current case. Please help.
FormattedText formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 16, Brushes.Black);
dc.DrawText(formattedText, new Point((tickFrequencySize * i), 30)); //dc is Drawing Context.
这是完整的课程:
public class CustomTickBar : TickBar
{
public static string FontTextList { get; set; }
protected override void OnRender(DrawingContext dc)
{
//string str = "Small, Medium, Large, Extra\n Large";
if (!string.IsNullOrEmpty(FontTextList))
{
string[] ar = FontTextList.Split(',');
Size size = new Size(base.ActualWidth, base.ActualHeight);
int tickCount = (int)((this.Maximum - this.Minimum) / this.TickFrequency) + 1;
//int tickCount = 4;
if ((this.Maximum - this.Minimum) % this.TickFrequency == 0)
tickCount -= 1;
Double tickFrequencySize;
// Calculate tick's setting
tickFrequencySize = (size.Width * this.TickFrequency / (this.Maximum - this.Minimum));
string text = "";
FormattedText formattedText = null;
double num = this.Maximum - this.Minimum;
int i = 0;
// Draw each tick text
for (i = 0; i <= tickCount; i++)
{
//text = Convert.ToString(Convert.ToInt32(this.Minimum + this.TickFrequency * i), 10);
text = ar[i];
formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 16, Brushes.Black);
dc.DrawText(formattedText, new Point((tickFrequencySize * i), 30));
}
}
}
推荐答案
尝试一下:
FormattedText formattedText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight, new Typeface("Verdana"), 16, Brushes.Black,
VisualTreeHelper.GetDpi(this).PixelsPerDip);
这篇关于FormattedText.FormttedText已过时.使用PixelsPerDip替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!