欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

wpf - Text Viewer

程序员文章站 2024-01-20 22:27:10
...

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://*.com/questions/1981137/c-sharp-wpf-scrollviewer-textblock-troubles-->

转载于:https://my.oschina.net/u/854138/blog/130767