WPF Textblock, linebreak in Text attribute
Try this: <TextBlock> line1 <LineBreak /> line2 </TextBlock>
Try this: <TextBlock> line1 <LineBreak /> line2 </TextBlock>
You can try putting a new line in the data: <data>Foo bar baz baz bar</data> If that does not work you might need to parse the string manually. If you need direct XAML that’s easy by the way: <TextBlock> Lorem <LineBreak/> Ipsum </TextBlock>
TextBlock is not a control Even though TextBlock lives in the System.Windows.Controls namespace, it is not a control. It derives directly from FrameworkElement. Label, on the other hand, derives from ContentControl. This means that Label can: Be given a custom control template (via the Template property). Display data other than just a string (via the … Read more
You can use a MultiBinding combined with the StringFormat property. Usage would resemble the following: <TextBlock> <TextBlock.Text> <MultiBinding StringFormat=”{}{0} + {1}”> <Binding Path=”Name” /> <Binding Path=”ID” /> </MultiBinding> </TextBlock.Text> </TextBlock> Giving Name a value of Foo and ID a value of 1, your output in the TextBlock would then be Foo + 1. Note: This … Read more
A Textblock itself can’t do vertical alignment The best way to do this that I’ve found is to put the textblock inside a border, so the border does the alignment for you. <Border BorderBrush=”{x:Null}” Height=”50″> <TextBlock TextWrapping=”Wrap” Text=”Some Text” VerticalAlignment=”Center”/> </Border> Note: This is functionally equivalent to using a grid, it just depends how you … Read more
Use a TextBox with these settings instead to make it read only and to look like a TextBlock control. <TextBox Background=”Transparent” BorderThickness=”0″ Text=”{Binding Text, Mode=OneWay}” IsReadOnly=”True” TextWrapping=”Wrap” />
Wrap it in a scroll viewer: <ScrollViewer> <TextBlock /> </ScrollViewer> NOTE this answer applies to a TextBlock (a read-only text element) as asked for in the original question. If you want to show scroll bars in a TextBox (an editable text element) then use the ScrollViewer attached properties: <TextBox ScrollViewer.HorizontalScrollBarVisibility=”Disabled” ScrollViewer.VerticalScrollBarVisibility=”Auto” /> Valid values for … Read more