WPF에서이 작업을 수행 할 내장 함수가 있다고 생각하지 않지만 잘못된 것일 수 있습니다.
아래 코드는이를 위해 사용자가 직접 컨트롤을 작성하는 방법을 보여줍니다. 그것은 효율적이지이며, 글꼴 등등을 제어하기 위해 더 많은 속성을 포함, 조정이 함께 할 수있는,하지만 당신은 아이디어를 얻을 :
SpacedTextBlock.cs :
public class SpacedTextBlock : Control
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text",
typeof(string),
typeof(SpacedTextBlock));
public string Text
{
get { return GetValue(TextProperty) as string; }
set { SetValue(TextProperty, value); }
}
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
if (Text != null)
{
var widthPerChar = ActualWidth/Text.Length;
var currentPosition = 0d;
foreach (var ch in Text)
{
drawingContext.DrawText(new FormattedText(ch.ToString(), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Foreground), new Point(currentPosition, 0));
currentPosition += widthPerChar;
}
}
}
}
Window1.xaml를 :
<local:SpacedTextBlock Text="Hello"/>
결과 :
alt text http://img199.imageshack.us/img199/8022/screenshotud.png
흥미 롭습니다. 사용자 정의 글꼴과 색상을 지원하기 위해 더 많은 코드를 추가해야합니다. 감사. –