0
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="200" Width="200">
<Grid>
    <Label Content="I am very very very long sentence you have ever seen">
        <Label.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="TextWrapping" Value="Wrap" />
            </Style>
        </Label.Resources>
    </Label>
</Grid>
</Window>

The above code doesnt work.

So, how to integrate TextBlock wrapping property to a Label?

1 Answers1

0

Put a TextBlock into the Label's Content:

<Label>
    <TextBlock Text="I am very very very long sentence you have ever seen"
               TextWrapping="Wrap"/>
</Label>

If you want to keep the Content property settable (e.g. by a Binding), put the TextBlock into the Label's ContentTemplate:

<Label Content="I am very very very long sentence you have ever seen">
    <Label.ContentTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" TextWrapping="Wrap"/>
        </DataTemplate>
    </Label.ContentTemplate>
</Label>

The question is, for what reason do you have a Label at all?

Clemens
  • 123,504
  • 12
  • 155
  • 268