我正在尝试将标签填充到水平滑块,并且TickBar
通过将 Text 传递给 FormattedText 构造函数的派生类,我成功地做到了这一点。但是现在,当我将相同的代码粘贴到使用 .NET Framework 4.6.2 版的 Visual Studio 中时,它会显示:
FormattedText.FormttedText 已过时。使用 PixelsPerDip 覆盖。
我提到在 .NET Framework 4.6.2 中 FormattedText() 已过时,我该如何修复它
但在目前的情况下,我该如何使用它。请帮忙。
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));
}
}
}