Does anyone know how to set the height of inside ? I tried to change the font size of...">

How to set height <Linebreak / ">

Does anyone know how to set the height of <LineBreak /> inside <TextBlock /> ? I tried to change the font size of the TextBlock , but that didn't help me.

UPDATE

I need to reduce it, not increase it.

+8
c # text wpf
source share
3 answers

The only way. One of the possibilities that I see is to use FlowDocumentScrollViewer as the content of your TextBlock. This will allow you to use a FlowDocument , which has a Paragraph , which has the FontSize and LineHeight properties. This will give you the opportunity to some extent change the height of LineBreak, it 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> 

It gave me such a result.

enter image description here


To add additional information. I suppose most of the gap you see between the lines is related to the LineHeight of the text lines. I played with him a little more and came up with this. It also has the added benefit that it doesn’t need workflow.

 <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> 

It gave me a result that looks like this. This will allow you to go less than you could

enter image description here

+7
source share

Here is the terrible hack I came across when faced with the same problem:

 // close out paragraph and move to next line textBlock.Inlines.Add(new LineBreak()); var span = new Span(); // use a smaller size so there less of a gap to the next paragraph span.FontSize = 4; // super awful hack. Using a space here won't work, but tab does span.Inlines.Add(new Run("\t")); // now the height of this line break will be governed by the font size we set above, not by the font size of the main text span.Inlines.Add(new LineBreak()); textBlock.Inlines.Add(span); 
0
source share

I had the same problem, for me it was easiest to use a TextBlock for each line, give the TextBlock the value of the bottom field 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 clear it by putting the field style in the share.

Quick and dirty, but it worked for my purposes.

enter image description here

0
source share

All Articles