我有一个用户控件,里面有一个TextBlock(textmsg),以下是xaml文件
<UserControl x:Class="XXXXX.MyMsgBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="400" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" Background="#FF000000">
<StackPanel HorizontalAlignment="Left" Name="stackPanel2" VerticalAlignment="Top" Margin="10">
<TextBlock Margin="10" Name="textmsg" Text="{Binding Path=LocalizedResources.wb_msg, Source={StaticResource LocalizedStrings}}" TextWrapping="Wrap" />
<StackPanel Name="stackPanel1" Orientation="Horizontal">
<Button Width="140" Content="{Binding Path=LocalizedResources.set_wb, Source={StaticResource LocalizedStrings}}" Name="button1" Click="button1_Click" FontSize="22" />
<Button Width="170" Content="{Binding Path=LocalizedResources.default_wb, Source={StaticResource LocalizedStrings}}" Name="button2" FontSize="22" />
<Button Width="140" Content="{Binding Path=LocalizedResources.cancel, Source={StaticResource LocalizedStrings}}" Height="72" Name="button3" FontSize="22" />
</StackPanel>
</StackPanel>
</Grid>
</UserControl>
然后在C#中我使用以下代码显示弹出窗口
Popup popup = new Popup();
MyMsgBox mmb = new MyMsgBox(popup);
popup.Height = 400;
popup.VerticalOffset = 328;
popup.HorizontalOffset = 0;
popup.Child = mmb;
popup.IsOpen = true;
但是textmsg里面的文字没有被包裹,为什么?有什么问题?
最好的问候。
答案 0 :(得分:0)
您应该在 TextBlock(textmsg)的父( StackPanel )上设置 MaxWidth 属性。 StackPanel大小与其内容要求的大小不同,并为内容提供任意内容的免费统治。因此,TextBlock要求文本的整个宽度没有包装。