Tutorial :WPF flush right text - possible easily?


This is a nice-to-have for our designer. She has a layout where a form title, on the top right of the form banner, is two words in English. There are several forms so the words are a little different each time. So the effect is something like:

|    firstword|  |         form|  

There is a fancy swoopy thing underneath this and some other fields to the left. Of course with several different forms, the words are different lengths, so sometimes the words are on one line, because they fit in the width:

|   short form|  

She wants the words to always be on two lines, basically classic 'flush right'. AFAIK this isn't really possible, especially with localization. If you get fancy with some codebehind that replaces the spaces with linebreaks, you'll have words that disappear or don't use all the space in localization.

So my question is if there is a way in WPF (maybe in some of those typography functions) to get a flush right look easily--if the word 'form' is always on the bottom and flush right, with whatever other words above flush right.


Sounds like the data that make up the 2 lines is separate ahead of time. As such it would be best to keep it separate rather than have it combined only to have to parse out later. Which I think is what led you to where you are now.

If the data is kept separate then you don't need to worry about trailing spaces (or it is easily trimmed). Simply stick a line feed in there when putting it to the display.


Something like this?

   <StackPanel Name="StackPanel1">          <WrapPanel Name="WrapPanel1" HorizontalAlignment="Right">              <TextBlock Name="TextBlock2"  HorizontalAlignment="Right" TextWrapping="Wrap">                  <TextBlock.Text>                      Lorum Ipsum Dolum Lorum Ipsum Dolum Lorum Ipsum Dolum Lorum Ipsum Dolum Lorum Ipsum Dolum Lorum Ipsum Dolum                   </TextBlock.Text>              </TextBlock>          </WrapPanel>               <TextBlock Height="23" Name="TextBlock1" Text="Form" HorizontalAlignment="Right" />     </StackPanel>  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »