wpf - Text Viewer

You might need to present some document or embed some readable content to the Reader. More often than not the information will be in text format, and we might want to have the ability to allow user to scroll either vertically or horizontally;

For one, if you have some fixed source (from File or some other persited source), you might give a try to the DocumentViewer, which has a Document property (which can host a FixedDocument or a XpsDocument). 

Or for some simpler use case, you just want to have such a View port of the text, and the Text does not requires such complex treatment such as pagination or else, you can embed a textBox inside a ScrollViewer, which has the scrollbar (horizontally and the Vertically) built-in, here is one paradigm to use the this pattern: 

<ScrollViewer  Grid.Column="2" Grid.Row="0"
                       HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" 
                       x:Name="Scroller"
                       >
            <TextBox x:Name="txtTemplate" 
                     HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                     MinWidth="100" Width="{Binding ElementName=Scroller, Path=ViewportWidth}" TextWrapping="Wrap"
                     />
        </ScrollViewer>

there are other Viewer, such as ViewBox (which seems too pristine?) Check more information in the comment below. 

<!-- ViewBox ??-->
        <!-- DocumentViewer ??-->
        <!--http://stackoverflow.com/questions/1981137/c-sharp-wpf-scrollviewer-textblock-troubles-->

你可能感兴趣的:(WPF)