Obviously, the only solution is to split the text string into words and layout words by column (as suggested by Jeff Yates above). The first thing to check using the Grid container:
<Grid Name="grid1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <TextBlock HorizontalAlignment="Left" Text="This" Grid.Column="0" /> <TextBlock HorizontalAlignment="Center" Text="is" Grid.Column="2" /> <TextBlock HorizontalAlignment="Center" Text="someprettylongpiece" Grid.Column="4" /> <TextBlock HorizontalAlignment="Right" Text="text" Grid.Column="6" /> </Grid>
The next step is to create a custom panel that composes text blocks without dealing with the grid:
<JustifiedPanel> <TextBlock Text="This"/> <TextBlock Text="is"/> <TextBlock Text="a"/> <TextBlock Text="justified"/> <TextBlock Text="line"/> <TextBlock Text="of"/> <TextBlock Text="text"/> <TextBlock Text="that"/> <TextBlock Text="demonstrates"/> <TextBlock Text="feasibility"/> </JustifiedPanel>
(Sample source code is available on my blog ) Finally, I am going to create a JustifiedTextBlock control that will split the text into words and place them. The nontrivial things here are proper RTL support and proper line breaks.
olegz source share