문제

I have a RichTextBlock with some text.I dont want use vertical and horizontal scrolls. If I add a large text, some text is hiding. How can I get hidden text or how can I get current not hided text? Size of my RichTextBlock set dynamically. TextWrapping="Wrap" is set.

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

codebehind:

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); } 
도움이 되었습니까?

해결책

I wonder if RichTextBlockOverflow could somehow help you there. Otherwise - you'd need to keep adding more text and see when it starts overflowing by calling Measure()+Arrange() and checking ActualWidth/ActualHeight. If that sounds clunky - you could use DirectWrite instead, which might be faster and better suited to handling custom layouts.

다른 팁

Make sure you haven't accidentally set the wrapping to no wrap. Also, is the box constrained on any way?

by default text wrapping is set to true:

<RichTextBlock TextWrapping="Wrap"/>

TextWrapping documentation on msdn

Using the code you posted:

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

And codebehind:

    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); 
    } 
}

The code wraps fine. Image:

enter image description here

Wrapping is affected by surrounding containing, paste some code and we might be able to help.

If the row is constricted, the box and its contents will as well.

Last edit, with large text you will get problems. Large text problem

Play around with the ViewBox and stretch properties to get the desired effect, maybe something like:

        <Viewbox  Grid.Row="1" StretchDirection="DownOnly">
        <RichTextBlock FontSize="65" Width="3000" x:Name="BookViewer">
        </RichTextBlock>
    </Viewbox>

Result: enter image description here

You should be able to take it from here :) Best of luck. Keep in mind that you need to set a restricting container inside the viewbox to get the wrapping.

Documentation: ViewBox

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top