TOC

This article has been localized into Vietnamese by the community.

Các điều khiển Rich Text:

Điều khiển FlowDocumentReader

FlowDocumentReader chắc chắn là wrapper read-only tiên tiến nhất mà bạn có thể đặt xung quanh một FlowDocument. Nó cung cấp các nút bấm cho phép người dùng có thể chuyển đổi giữa các chế độ render cung cấp bởi FlowDocumentScrollViewer và FlowDocumentPageViewer, cũng như tính năng tìm kiếm ngoại vi và tất nhiên là chức năng phóng to/thu nhỏ.

Tất cả các tính năng này biến FlowDocumentReader thành một trong ba wrapper read-only nặng nhất, nhưng điều này không phải là một vấn đề với các tài liệu có kích cỡ thông thường. Dưới đây là một ví dụ về FlowDocumentReader:

Ảnh chụp màn hình này được chụp trong một chế độ xem page-based - chế độ xem mặc định. Bạn có thể chuyển đổi giữa các chế độ xem sử dụng các nút ở phía bên trái của thanh zoom. Ở phía bên trái của toolbar, bạn có các control để tìm kiếm trong tài liệu, như cách tôi đã thể hiện ở đây.

Dưới đây là đoạn code để có được kết quả như ở trên:

<Window x:Class="WpfTutorialSamples.Rich_text_controls.FlowDocumentReaderSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="FlowDocumentReaderSample" Height="250" Width="550">
    <Grid>
        <FlowDocumentReader>
            <FlowDocument>
                <Paragraph>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce faucibus odio arcu, luctus vestibulum tortor congue in. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec lacinia neque. Donec malesuada, ligula non vestibulum cursus, urna purus pellentesque orci, aliquet accumsan dui velit ac justo. Phasellus sagittis ligula in leo dapibus, vel vestibulum felis mattis. Fusce vitae auctor nibh. Ut sit amet fringilla turpis. Aenean tincidunt feugiat sapien, quis scelerisque enim pretium commodo. Mauris fermentum posuere nulla, vitae fermentum quam malesuada in. Cras ultrices bibendum nulla eu mollis. Sed accumsan pretium magna, non sodales velit viverra id. Sed eu elit sit amet sem ullamcorper rhoncus.</Paragraph>
                <Paragraph>Nulla vitae suscipit tellus. Nunc sit amet tortor fermentum, sollicitudin enim cursus, sagittis lacus. Pellentesque tincidunt massa nisl, nec tempor nulla consequat a. Proin pharetra neque vel dolor congue, at condimentum arcu varius. Sed vel luctus enim. Curabitur eleifend dui et arcu faucibus, sit amet vulputate libero suscipit. Vestibulum ultrices nisi id metus ultrices, eu ultricies ligula rutrum. Phasellus rhoncus aliquam pretium. Quisque in nunc erat. Etiam mollis turpis cursus, sagittis felis vel, dignissim risus. Ut at est nec tellus lobortis venenatis. Fusce elit mi, gravida sed tortor at, faucibus interdum felis. Phasellus porttitor dolor in nunc pellentesque, eu hendrerit nulla porta. Vestibulum cursus placerat elit. Nullam malesuada dictum venenatis. Interdum et malesuada fames ac ante ipsum primis in faucibus.</Paragraph>
            </FlowDocument>
        </FlowDocumentReader>
    </Grid>
</Window>

Đoạn code trên sẽ cho kết quả là cửa sổ bạn có thể thấy ở ảnh chụp màn hình trên. Dưới đây là một ảnh chụp màn hình khác đã được tôi đưa về chế độ xem chia đôi và giảm độ phóng to đi một chút:

FlowDocumentReader có nhiều thuộc tính có thể giúp bạn kiểm soát các mọi thứ hoạt động. Dưới đây là danh sách một số thuộc tính quan trọng:

ViewingMode - kiểm soát chế độ xem ban đầu. Chế độ mặc định là Page, nhưng bạn có thể thay đổi nó thành Scroll hoặc TwoPage nếu bạn muốn có một chế độ xem khác. Điều này có thể được thay đổi bởi người dùng, trừ khi bị vô hiệu hóa.

IsFindEnabled - cho phép bạn vô hiệu hóa tính năng tìm kiếm trong tài liệu. Khi bị vô hiệu hóa, nút tìm kiếm sẽ bị xóa khỏi toolbar.

IsTwoPageViewEnabled , IsPageViewEnabled IsScrollViewEnabled - cho phép bạn vô hiệu hóa một chế độ xem nhất định cho người đọc. Khi được gán giá trị false, chế độ xem này sẽ không còn có sẵn cho người đọc và nút tương đương sẽ bị loại khỏi toolbar.

Zoom - cho phép bạn đặt một giá trị zoom nhất định. Giá trị mặc định là 100% nhưng bạn có thể thay đổi giá trị này qua thuộc tính Zoom.

Kết luận

Chúng ta đã đi qua tất cả những điều cần biết về wrapper read-only FlowDocument, và như bạn có thể thấy, lựa chọn cho wrapper hoàn toàn phụ thuộc vào mục đích của người dùng.

Nếu bạn chị muốn FlowDocument hiện tài liệu với thanh cuộn thì bạn nên sử dụng FlowDocumentScrollViewer - nó rất dễ sử dụng và tiêu tốn ít tài nguyên nhất. Nếu bạn muốn có chế độ xem theo trang, dùng FlowDocumentPageViewer. Và nếu bạn muốn người dùng có thể chuyển đổi qua lại giữa các chế độ xem và tìm kiếm một cách nhanh chóng, trong trường hợp này bạn hãy dùng FlowDocumentReader.


This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!