title: FormattedText.FormttedText is obsolete. Use the PixelsPerDip override
body: <p>I am trying to populate labels to a horizontal slider and I was successfully able to do it using a class that derives from <code>TickBar</code> 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:</p>
  
  <p>FormattedText.FormttedText is obsolete. Use the PixelsPerDip override. </p>
  
  <p>I referred to <a href="https://stackoverflow.com/questions/40277388/in-net-framework-4-6-2-the-formattedtext-is-obsoleted-how-can-i-fixed-it">In .NET Framework 4.6.2 the FormattedText() is Obsoleted, how can i fixed it</a></p>
  
  <p>But how can I use that in this current case. Please help.</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Here is the complete class:</p>
  
  <pre><code>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 &lt;= 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));
  
  
                  }
              }
          }
  </code></pre>