确保您没有不小心将包装设置为无包装。另外,盒子是否受到任何限制?
默认情况下,文本换行设置为 true:
<RichTextBlock TextWrapping="Wrap"/>
msdn 上的 TextWrapping 文档
使用您发布的代码:
<Page
x:Class="Wrap.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Wrap"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<RichTextBlock x:Name="BookViewer"
HorizontalAlignment="Left"
Height="525"
Margin="63,0,0,0"
Grid.Row="1"
TextWrapping="Wrap"
VerticalAlignment="Top"
Width="1246" TextAlignment="Justify" >
</RichTextBlock>
</Grid>
和代码隐藏:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
var str = "Bacon ipsum dolor sit amet ball tip tenderloin pork loin, tri-tip beef jowl pork belly capicola beef ribs ham bacon pig. Pork chop ball tip leberkas spare ribs pork belly pastrami shoulder ham hock andouille kielbasa short loin corned beef tenderloin chicken venison. Sausage jowl beef salami spare ribs ball tip. Swine brisket pancetta biltong shankle rump ground round jerky sausage. Rump beef chuck, salami leberkas jowl hamburger pancetta short loin tenderloin swine ground round ham. Meatloaf ball tip flank short loin boudin brisket t-bone pork chop." +
"Rump tri-tip pork drumstick kielbasa tenderloin shank beef ribs pig prosciutto swine spare ribs meatball ham. Pork pork loin t-bone, chicken turducken pork belly meatloaf bacon shankle sirloin pancetta shank drumstick. Kielbasa doner shoulder turducken sirloin pancetta, venison bacon corned beef beef pork belly shank. Bresaola drumstick short ribs t-bone. Tenderloin biltong salami, swine kielbasa shoulder short loin sirloin turducken capicola. Cow tri-tip jowl ground round short loin tail. Ribeye corned beef ball tip pork belly swine capicola chuck." +
"Rump tri-tip pork drumstick kielbasa tenderloin shank beef ribs pig prosciutto swine spare ribs meatball ham. Pork pork loin t-bone, chicken turducken pork belly meatloaf bacon shankle sirloin pancetta shank drumstick. Kielbasa doner shoulder turducken sirloin pancetta, venison bacon corned beef beef pork belly shank. Bresaola drumstick short ribs t-bone. Tenderloin biltong salami, swine kielbasa shoulder short loin sirloin turducken capicola. Cow tri-tip jowl ground round short loin tail. Ribeye corned beef ball tip pork belly swine capicola chuck.";
SetText(str);
}
private void SetText(string value)
{
BookViewer.Blocks.Clear();
Run myRun = new Run();
myRun.Text = value;
Paragraph myParagraph = new Paragraph();
myParagraph.Inlines.Add(myRun); BookViewer.Blocks.Add(myParagraph);
}
}
代码包装得很好。图片:
包装受周围包含的影响,粘贴一些代码,我们可能会提供帮助。
如果行被压缩,盒子和它的内容也会被压缩。
最后编辑,大文本你会遇到问题。
使用 ViewBox 和拉伸属性来获得所需的效果,可能类似于:
<Viewbox Grid.Row="1" StretchDirection="DownOnly">
<RichTextBlock FontSize="65" Width="3000" x:Name="BookViewer">
</RichTextBlock>
</Viewbox>
结果:
你应该可以从这里拿走它:) 祝你好运。请记住,您需要在视图框内设置一个限制容器才能获得包装。
文档:ViewBox