简体   繁体   中英

TextBlock not wrapping inside grid column windows phone

I've the following xaml definition. The textblock inside the stackpanel is not wrapping.

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

    <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <toolkit:PhoneTextBox x:Name="NotesText" Grid.Row="0" Grid.ColumnSpan="2" Hint="Add Notes" AcceptsReturn="True" Height="290" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" />
        <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" >
            <CheckBox x:Name="showRequester" FontSize="{StaticResource PhoneFontSizeSmall}" HorizontalAlignment="Left" />
            <TextBlock TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" Text="option_show_to_requester" />
        </StackPanel>
        <CheckBox Grid.Row="1" Grid.Column="1" Content="Mail To Technicain" FontSize="{StaticResource PhoneFontSizeSmall}" HorizontalAlignment="Right" />

    </Grid>

注意文本块超出列

What I should do to make it wrap ? Thanks.

Update: 在此处输入图片说明

Problem with the alignment when using data template for check box content.

您可以通过提供TextBlock Width来解决此问题。

You don't need to put a checkBox and a TextBlock into a StackPanel . To make the CheckBox's content Wrap , just use ContentTemplate of CheckBox.

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <toolkit:PhoneTextBox x:Name="NotesText" Grid.Row="0" Grid.ColumnSpan="2" Hint="Add Notes" AcceptsReturn="True" Height="290" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" />
        <!--Use ContentTemplate of CheckBox-->
        <CheckBox Grid.Row="1" Grid.Column="0">
            <CheckBox.ContentTemplate>
                <DataTemplate>
                    <TextBlock Text="option_show_to_requester" TextWrapping="Wrap"/>
                </DataTemplate>
            </CheckBox.ContentTemplate>
        </CheckBox>
        <CheckBox Grid.Row="1" Grid.Column="1" Content="Mail To Technicain" FontSize="{StaticResource PhoneFontSizeSmall}" HorizontalAlignment="Right" />

    </Grid>

for a simple example:

<Grid Grid.Row="1" x:Name="ContentRoot" Tapped="ContentRoot_Tapped">             
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto" />
        <RowDefinition Height="auto" />
        <RowDefinition Height="auto" />
    </Grid.RowDefinitions>
    <CheckBox Grid.Column="0">
        <CheckBox.ContentTemplate>
            <DataTemplate>
                <TextBlock TextAlignment="Center" Text="wrap123123123123wrap" TextWrapping="Wrap"/>     
            </DataTemplate>
        </CheckBox.ContentTemplate>
    </CheckBox>
    <CheckBox Grid.Column="1">
        <CheckBox.ContentTemplate>
            <DataTemplate>
                <TextBlock Text="nowrap" TextWrapping="Wrap"/>
            </DataTemplate>
        </CheckBox.ContentTemplate>
    </CheckBox>            
</Grid>

And the run image is: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM