nibill
nibill

Reputation: 13

How do I get line break in textBlock working

I somehow can't seem to get a line break in my TextBlock.

TextWrapping="Wrap" doesn't work. Also anything else such as TextTrimming doesn't affect my TextBlock at all. I assume an other control is blocking? Talking about the "txtErrorLabel"

<Window x:Class="BLVKServiceDashboard.Pages.ErrorWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ErrorWindow" Height="555" Width="420" Icon="/BLVKServiceDashboard;component/error.ico" ResizeMode="NoResize" WindowStartupLocation="Manual" ShowInTaskbar="False" Background="#FFEEEEEE" WindowStyle="None">
<Grid Margin="0,0,4,-3" RenderTransformOrigin="0.588,0.554">
    <Label Content="Fehlermeldungen" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" FontFamily="Segoe UI Semibold" FontSize="25"/>

    <ListBox x:Name="lstErrorItems" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" Background="{x:Null}" Margin="0,58" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid Width="500" Height="38" Margin="0,0,0,0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="380"/>
                        <ColumnDefinition Width="120"/>
                    </Grid.ColumnDefinitions>
                    <ScrollViewer Grid.ColumnSpan="2">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Foreground="Black" Text="Fehler: " HorizontalAlignment="Left" Height="Auto" Width="Auto" VerticalAlignment="Top"  Margin="5,10,0,2" FontSize="14" FontFamily="Segoe UI" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
                            <TextBlock x:Name="txtErrorLabel" Foreground="Black" Text="{Binding}" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Margin="5,10,0,2" FontSize="14" FontFamily="Segoe UI"/>
                        </StackPanel>
                    </ScrollViewer>
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <Button x:Name="btnDelete" Content="Meldungen löschen" Margin="147,514,147,0" VerticalAlignment="Top" Width="122" Click="btnDelete_Click" HorizontalContentAlignment="Center" RenderTransformOrigin="0.467,0.909"/>
</Grid>

Upvotes: 1

Views: 319

Answers (1)

Muds
Muds

Reputation: 4116

Your textblock is in stackPanel which gives no boundary to your textBlock.

change parent to something which provides boundary to your textblock or set limits to stack panel itself.

TextWrapping will come into effect only when the textblock exceeds width of parent control. But stackPanel never imposes any boundary to its childs and hence all space is available.

a possible solution can be --

<Grid Width="500" Height="Auto" Margin="0,0,0,0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="380"/>
            <ColumnDefinition Width="120"/>
        </Grid.ColumnDefinitions>
        <ScrollViewer Grid.ColumnSpan="2">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock Foreground="Black" Text="Fehler: " HorizontalAlignment="Left" Height="Auto" Width="Auto" VerticalAlignment="Top"  Margin="5,10,0,2" FontSize="14" FontFamily="Segoe UI" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
                <TextBlock Grid.Column="1" x:Name="txtErrorLabel" 
                           Foreground="Black" 
                           TextWrapping="Wrap"
                           Text="123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Top" 
                           Margin="5,10,0,2" 
                           FontSize="14" FontFamily="Segoe UI"/>
            </Grid>
        </ScrollViewer>
    </Grid>

Upvotes: 1

Related Questions