Aleksandar Zoric
Aleksandar Zoric

Reputation: 1483

Text in label being cut off

Consider the below WPF -

enter image description here

The issue is the text that appears in the label is being cut off if it is longer than the width of the label.

XAML - label name is 'factTxt'

<Window x:Name="mainScreen" x:Class="FactsOnAll.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:FactsOnAll"
        mc:Ignorable="d"
        Title="Random Facts" Height="450" Width="800" Icon="Properties/checklist.png">
    <Grid>
        <Button x:Name="getFactBtn" Content="Get Random Fact" HorizontalAlignment="Left" Margin="304,331,0,0" VerticalAlignment="Top" Width="177" Click="getFactBtn_Click" FontSize="20" Background="#FF8ECF87" Foreground="#FF444444"/>
        <Label x:Name="factTxt" Content="" Margin="10,98,10,0" VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="20"/>
        <Label x:Name="titleTxt" Content="Random Facts" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="772" Height="46" FontSize="24"/>

    </Grid>
</Window>

Expect result

Allow the text to go to a new line. I thought increasing the height of the label would fix this but no luck.

Upvotes: 0

Views: 5333

Answers (1)

juri
juri

Reputation: 38

The Label has no wrapping but a TextBlock. You can just create custom content like, that will wrap automatically:

<Label Width="100">
  <TextBlock Text="Get Random Fact" TextWrapping="Wrap"/>
</Label>

Upvotes: 2

Related Questions