Text in StackPanel doesn't wrap (wp7)

淺唱寂寞╮ 提交于 2019-12-05 19:00:57

A StackPanel will give its components infinite height or width depending on the Orientation.

If I look at your XAML I would suggest to use two columns in the grid, and put the image on the left side:

<ListBox.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions >
                <RowDefinition Height="60"/>
                <RowDefinition Height="170"/>
                <RowDefinition Height="50"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.ColumnSpan="2"></TextBlock>
            <TextBlock Grid.Row="1" Grid.ColumnSpan="2"></TextBlock>
            <TextBlock Grid.Row="2" Grid.ColumnSpan="2"></TextBlock>
            <Image Grid.Row="3" Source="Picture.png" MaxHeight="20" HorizontalAlignment="Center" Margin="0,20,0,0" />
            <TextBlock Grid.Column="1" Grid.Row="3" Text="Long long long text from Binding" FontSize="25" 
                        HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" 
                        VerticalAlignment="Bottom" Padding="20,10,0,0"  />
        </Grid>
    </DataTemplate>
</ListBox.ItemTemplate>

Notice Grid.ColumnSpan on the first textboxes, this will span them over the entire width of the grid, not just the first column.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!