是否可以使文本在边框内换行? WPF

Is it possible to make text wrap inside of a border? WPF

我有这样的东西:

<ControlTemplate>
                <StackPanel Orientation="Horizontal">
                    <!--Icon-->
                        <Ellipse Width="30" Height="30" Margin="10,0,0,-5">
                        <Ellipse.Fill>
                            <ImageBrush ImageSource="{Binding ImageSource}"
                                        RenderOptions.BitmapScalingMode="Fant"/>
                        </Ellipse.Fill>
                    </Ellipse>
                    
                    <!--Surround Info-->
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{Binding Name}"
                                      Foreground="{Binding UserNameColor}"
                                      FontWeight="SemiBold"
                                      VerticalAlignment="Center"
                                      Margin="0,0,-5,0"/>
                            <Label Content="{Binding Date}"
                                      Foreground="White"
                                      FontWeight="SemiBold"
                                      FontSize="8"
                                      VerticalAlignment="Center"
                                      Margin="0,0,-5,0"/>
                        </StackPanel>
                        
                        <!--Message-->

                        
                        <Border VerticalAlignment="Center" CornerRadius="10 15 15 0" Margin="2 2 88 3" Background="LightSlateGray">
                            <TextBlock Foreground="White" Margin="7" TextWrapping="Wrap" FontWeight="SemiBold" Text="{Binding Content}"/>
                        </Border>
                    </StackPanel>
                </StackPanel>
            </ControlTemplate>

我需要文本块用里面的文本包裹,但我不知道如何在不给出我不想要的边框宽度的情况下这样做

我想实现这样的目标:

您似乎在 StackPanel 内部使用 StackPanel。 有一个已知问题,StackPanel 将收到其父级的调整大小事件,但仅当大小增加时。 参考:

我建议使用其他元素,例如 Grid。

<Window x:Class="WpfSandbox.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                
    Title="MainWindow" Height="450" Width="300">
<Grid Background="#292B2F" x:Name="OuterGrid">
    <!--Surround Info-->
    <Grid Margin="10">
        <StackPanel>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Label Content="Name" Foreground="Gray" FontWeight="SemiBold" VerticalAlignment="Center" Margin="0,0,-5,0" />
                <Label Content="2021/10/29" Grid.Column="1" Foreground="White" FontWeight="SemiBold" FontSize="8" VerticalAlignment="Center" Margin="5,0,-5,0" />
            </Grid>

            <!--Message-->
            <Border VerticalAlignment="Center" CornerRadius="10 15 15 0" Margin="2 2 20 3" Background="LightSlateGray">
                <TextBlock Foreground="White" Margin="7" TextWrapping="Wrap" FontWeight="SemiBold"
                           Text="Blah blah blah yadda yadda yadda blah blah blah this is a really really long message that should wrap at some point, giving you the functionality you are after." />
            </Border>
        </StackPanel>
    </Grid>
</Grid>