i have a wpf window where i have a stackpanel with two viewports in it - each Viewport with a textblock in it.
<Grid> <StackPanel VerticalAlignment="Center" Orientation="Vertical" > <Viewbox Margin="100,0,100,0"> <TextBlock x:Name="headerText" Text="Lorem ipsum dolor" Foreground="Black"/> </Viewbox> <Viewbox Margin="150,0,150,0"> <TextBlock x:Name="subHeaderText" Text="Lorem ipsum dolor, Lorem ipsum dolor, lorem isum dolor, Lorem ipsum dolor, Lorem ipsum dolor, lorem isum dolor, " TextWrapping="Wrap" Foreground="Gray" /> </Viewbox> </StackPanel> </Grid>
What i would like to achieve is that the top textblock is the heading with a bigger text. The second textblock is the sub heading with a smaller text. No matter how much text there is for either the heading or the subheading the font should dynamic become smaller/bigger. My problem is that i would like the subheading to be fixed width. This means that, the font should be a percentage (70%) of the heading and wrap to multiple lines, depending on how much text i have. I enclosed the code I have thus far... im missing something with that subheading, cant figure out what. Cheers
Edit Basically what i want achieve is that the sub header wraps the text so it can expand it downwards with the font being a 70% of the heading - no matter how big that font is.
In WPF, the Label control does not support text wrapping. If you need a label that wraps contents across multiple lines, you can use a TextBlock control. Place a TextBlock control inside a Label and apply wrapping on TextBlock.
Adding Line Breaks Sometimes you will want to insert a line break within a TextBlock. You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element.
TextBlock is not editable.
To prevent users from modifying the contents of a TextBox control, set the IsReadOnly attribute to true.
Nesting a stackpanel will cause the textbox to wrap properly:
<Viewbox Margin="120,0,120,0"> <StackPanel Orientation="Vertical" Width="400"> <TextBlock x:Name="subHeaderText" FontSize="20" TextWrapping="Wrap" Foreground="Black" Text="Lorem ipsum dolor, lorem isum dolor,Lorem ipsum dolor sit amet, lorem ipsum dolor sit amet " /> </StackPanel> </Viewbox>
Use the property TextWrapping
of the TextBlock
element:
<TextBlock Text="StackOverflow Forum" Width="100" TextWrapping="WrapWithOverflow"/>
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