public string GetFont
(string str, string fontFamily, int nSize)
{
Typeface typeface =
new Typeface(new FontFamily(fontFamily),
FontStyles.Normal, FontWeights.Normal,
FontStretches.Normal);
FormattedText text = new FormattedText(str,
new System.Globalization.CultureInfo("zh-tw"),
FlowDirection.LeftToRight, typeface, nSize,
Brushes.Black);
Geometry geo = text.BuildGeometry(new Point(0, 0));
PathGeometry path = geo.GetFlattenedPathGeometry();
string data = path.ToString();
string xamlTriangle = "<Path xmlns='http://schemas.microsoft.com/" +
"winfx/2006/xaml/presentation' " +
"xmlns:x='http://schemas.microsoft.com/" +
"winfx/2006/xaml' " +
"Data='" + data + "' Fill='LightBlue' " +
"Stretch='Fill'/>";
return xamlTriangle;
}
而 Client 的程式如下:
void client_StringToPathCompleted(object sender,
DoWorkCompletedEventArgs e)
{
Path newPath = (Path)
System.Windows.Markup.XamlReader.Load(e.Result);
this.LayoutRoot.Children.Add(newPath);
}
[Reference]以 WPF + AJAX 在執行期間將文字轉成 Path
In SL3.0, can you not just use XamlReader.Load ?

