I have a user control that inside has a TextBlock (textmsg), the following is the xaml file
<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>
then in C# I use the following code to display the popup
Popup popup = new Popup();
MyMsgBox mmb = new MyMsgBox(popup);
popup.Height = 400;
popup.VerticalOffset = 328;
popup.HorizontalOffset = 0;
popup.Child = mmb;
popup.IsOpen = true;
but the text inside textmsg isn’t wrapped, why ? What is wrong?
Best regards.
You should set the MaxWidth property on the parent (StackPanel) of your TextBlock (textmsg). StackPanel sizes to whatever its content asks for, and gives free reign for the content to ask for anything. Thus, the TextBlock asks for the full width of the text with no wrapping.