TextBlock没有包装在网格列窗口手机内

时间:2014-06-17 13:00:39

标签: c# wpf xaml windows-phone-8 stackpanel

我有以下xaml定义。 stackpanel内的文本块没有包装。

<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>

Note the textblock stretching out of column

我应该怎么做才能包好?感谢。

更新: enter image description here

对复选框内容使用数据模板时的对齐问题。

2 个答案:

答案 0 :(得分:1)

您可以通过提供Width的{​​{1}}来解决此问题。

答案 1 :(得分:1)

您不需要put a checkBox and a TextBlock into a StackPanel。要使CheckBox的内容 Wrap ,只需使用CheckBox的 ContentTemplate

    <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>

一个简单的例子:

<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>

运行图像是: enter image description here