Multiline centered text using TextBlockVisual3D?
#1
I am using TextBlockVisual3D to display multline text (each line separated by \r\n).  I would like each line of text to be centered.  I've tried a few things, but nothing gave me the result that I am interested in.  What is the best way to display three lines of text with each line centered?  See the attached image for example.  I want HDPE, 19.87', and 134,840 lbs to be centered on that yellow cylinder.

Thanks,
Arthur


Attached Files Thumbnail(s)
   
#2
This is an interesting question.

With a standard TextBlock it is possible to achieve this with setting the TextAlignment to Center.

Currently the TextBlockVisual3D does not support TextAlignment. But because TextBlockVisual3D is highly customizable, you can set that property to the underlying TextBlock with using a derived class:

Code:
   public class CenteredTextBlockVisual3D : TextBlockVisual3D
   {
       // To add some customization to how TextBlock is rendered,
       // you can override the UpdateTextBlock
       protected override void UpdateTextBlock()
       {
           base.UpdateTextBlock();

           textBlock.TextAlignment = TextAlignment.Center;
       }
   }

Then just use the CenteredTextBlockVisual3D instead of the standard TextBlockVisual3D.

In similar way it is also possible to customize the Border and Plane's MeshGeometry3D - see the CustomTextBlockVisual3DSample for more info.


I see that the TextAlignment can be useful for other users also. Therefore I have added it to the TextBlockVisual3D so it will be available in the next version of Ab3d.PowerToys library.
Andrej Benedik
#3
Thank you, that works well!
  


Forum Jump:


Users browsing this thread:
1 Guest(s)