hi Stoyan,
I try as you told, but I find when I change the node's size, the text will out of the node? could you please tell how to solve it ?
public FormattedText GetFormattedText()
{
FormattedText formattedText = new FormattedText(this.Text,
CultureInfo.GetCultureInfo(CultureInfo.CurrentCulture.ToString()), FlowDirection,
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch), FontSize,
Brushes.Black);
formattedText.SetFontSize(FontSize, 0, 0);
formattedText.SetFontWeight(FontWeight, 0, 0);
formattedText.SetForegroundBrush(Brushes.Black);
formattedText.SetFontStyle(FontStyle, 0, 0);
formattedText.TextAlignment = TextAlignment;
textStartX = 0;
if (TextVerticalAlignment == AlignmentY.Top)
{
textStartY = 0;
}
else if (TextVerticalAlignment == AlignmentY.Center)
{
textStartY = Bounds.Height / 2 - formattedText.Height / 2;
}
else
{
textStartY = Bounds.Height - formattedText.Height;
}
textSize.Width = formattedText.Width;
textSize.Height = formattedText.Height;
return formattedText;
}
public override void Draw(DrawingContext graphics, RenderOptions options)
{
FormattedText tempFormattedText = GetFormattedText();
Size tempBounds = this.Bounds.Size;
if (this.Bounds.Size.Height < textSize.Height || this.Bounds.Size.Width < textSize.Width)
{
tempBounds.Height = textSize.Height > this.Bounds.Size.Height ? textSize.Height : this.Bounds.Size.Height;
tempBounds.Width = textSize.Width > this.Bounds.Size.Width ? textSize.Width : this.Bounds.Size.Width;
}
graphics.DrawRectangle(EvBrush, EvPen, new Rect(new Point(0, 0), tempBounds));
tempFormattedText.MaxTextWidth = Bounds.Height;
tempFormattedText.MaxTextHeight = Bounds.Width;
RotateTransform rotateTransform = new RotateTransform(90, tempBounds.Width / 2, tempBounds.Height / 2);
graphics.PushTransform(rotateTransform);
graphics.DrawText(tempFormattedText, new Point(textStartX, textStartY));
graphics.Pop();
this.AnchorPattern = new AnchorPattern();
AnchorPattern.Points.Add(new AnchorPoint(0, 50, true, false, MarkStyle.None));
AnchorPattern.Points.Add(new AnchorPoint(100, 50, false, true, MarkStyle.None));
}
}
]