TextBlock not wrapping inside grid column windows phone

倾然丶 夕夏残阳落幕 提交于 2019-12-11 08:33:24

问题


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.


回答1:


You can solve this by Providing Width of TextBlock.




回答2:


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:



来源:https://stackoverflow.com/questions/24264533/textblock-not-wrapping-inside-grid-column-windows-phone

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