Does anybody know how to set up height of <LineBreak />
inside <TextBlock />
? I tried to change font size of TextBlock
but it's didn't help me.
UPDATE
I need to decrease it, not increase.
The only way One of the possibility's that I can see are to use FlowDocumentScrollViewer as the Content of your TextBlock. It will allow you to use a FlowDocument which has a Paragraph object which has FontSize and LineHeight Property's. This will give you the ability to change the Height of the LineBreak to a certain extent, this may not be as small as you want.
<Grid>
<TextBlock LineHeight="1" Height="85" Width="400" HorizontalAlignment="Left" Margin="12,29,0,0" Name="textBlock1" VerticalAlignment="Top" Background="Beige" >
<FlowDocumentScrollViewer Width="400" VerticalScrollBarVisibility="Hidden" >
<FlowDocument>
<Paragraph LineHeight="1" FontSize="12" FontFamily="Arial" Foreground="Red" >
<Run> This is a Test of line height</Run>
</Paragraph>
<Paragraph LineHeight="1" FontSize="1" BorderThickness=" 1" BorderBrush="Black">
<LineBreak/>
</Paragraph >
<Paragraph LineHeight="1" FontSize="12" FontFamily="Arial" Foreground="Blue">
<Run> This is a Test of line height</Run>
</Paragraph>
<Paragraph LineHeight="1" FontSize="2" BorderThickness=" 1" BorderBrush="Black">
<LineBreak />
</Paragraph>
<Paragraph LineHeight="1" FontSize="12" FontFamily="Arial" Foreground="Green" >
<Run> This is a Test of line height</Run>
</Paragraph>
<Paragraph LineHeight="1" FontSize="5" BorderThickness=" 1" BorderBrush="Black">
<LineBreak />
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
</TextBlock>
</Grid>
This gave me a result like this.
To add some additional information. I beleive most of the gap that you see between lines has to do with the LineHeight of the Text Lines. I played around with it a litte bit more and came up with this. It also has the added benefit of not needing a flow document.
<TextBlock LineHeight="9.75" LineStackingStrategy="BlockLineHeight" Margin="12,188,-12,-188">
<Run> This is a Test of Line Height</Run>
<LineBreak />
<Run >This is a Test of Line Height</Run>
<LineBreak />
<Run>This is a Test of Line Height</Run>
<LineBreak />
<Run> This is a Test of Line Height</Run>
</TextBlock>
This gave me a result that looks like this. It will allow you to go smaller than you could otherwise
I had the same problem, easiest workaround for me was to use a TextBlock for each line, give the TextBlock a bottom margin setting and contain them in a StackPanel.
<StackPanel>
<TextBlock Margin="0,0,0,10">
This is the text and this text is quite long so it wraps over the end of the line...
</TextBlock>
<TextBlock Margin="0,0,0,10">
This is the text and this text is quite long so it wraps over the end of the line...
</TextBlock>
</StackPanel>
You can clean it up by putting the margin style in a shared resource.
Quick and dirty but it worked for my purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With