silverlight - How to center text around point using xaml -


I want to be able to place the word "hello" centered on a particular point, I want to complete it without the extra code Need to do in XAML. Best I can say, all text alignment properties / styles work in XAML on some bound canvas or other elements inside the text.

Since I do not know the length of the text, so I can not focus on using my code.

The reason I need to solve this problem completely is that in XAMML, I am not using WPF to create XML, I am writing it directly in an XML DOM. It will then be loaded into a silverlight or WPF control to display.

In most of the graphic languages, including SVG, where my code is generated, text can be aligned with a "stationary point" without a bounding box.

(Yes, I know that this question is outdated.) < / P>

The effectiveness of this solution may vary with the version of Silverlight or the .NET Framework, and I have not run it with Silverlight for Windows Phone 7. I stand-alone WPF application, and I've written another version that also works in Silverlight. First of all, the version that works in Silverlight and WPF Please note that if you are not using the canvas to provide a full position for the center of your text block, It has to be a little refactor. For example, you can use Translation Transcens to move your text.

  & lt; Canvas & gt; & Lt; Canvas.Resources & gt; & Lt; ScaleTransform x: key = "transform" ScaleX = "- 1" ScaleY = "- 1" /> & Lt; /Canvas.Resources> & Lt; Grid Render Transform = "{Static Resource Transfer}" Render Transaction Engine = "- 25-0.25" & gt; & Lt; TextBlock RenderTransform = "{StaticResource transform}" & gt; Hello! & Lt; / TextBlock & gt; & Lt; / Grid & gt; & Lt; / Canvas & gt;  

Second, the version which works only in WPF does not work in Silverlight because it depends on the presence of canvas. Correct and canvas.bottom enclosed properties are not even in uniform grid silverlight, but this code could be replaced by a regular grid with 2 star-length rows and columns.

  & lt; Canvas & gt; & Lt; Uniform Grid Rows = "2" column = "2" datacentext = "{binding element name = text box 1}" width = "{binding path = real person}" height = "{binding path = real height}" & gt; & Lt; Canvas & gt; & Lt; TextBlockName = "textbox1" canvas Right = "0" canvas.bottom = "0" & ​​gt; Hello! & Lt; / TextBlock & gt; & Lt; / Canvas & gt; & Lt; / UniformGrid & gt; & Lt; / Canvas & gt;  

By the way, there can be more efficient ways to solve this problem. I do not give any guarantee!


Comments