65.9K
CodeProject 正在变化。 阅读更多。
Home

StackPanel 与 FlowDocumentReader

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.40/5 (2投票s)

2010年3月18日

CPOL

2分钟阅读

viewsIcon

23539

downloadIcon

453

我们将学习如何在 StackPanel 中使用 FlowDocumentReader。

WpfStackPanelExample

引言

这是我的第三篇文章,是在我前两篇文章的基础上构建的。 前两篇文章可以在这里找到:12。 在本文中,我们将学习 FlowDocumentReader 是什么以及如何将其与 StackPanel 一起使用,为您的 WPF 应用程序添加功能。

StackPanel 用于什么? StackPanel 允许开发人员以指定方向堆叠元素。 方向由 StackPanel 内部的属性定义。 StackPanels 主要用于列表框或组合框中,但在本例中,我们将 StackPanel FlowDocumentReader 控件一起使用。

你问,FlowDocumentReader 是什么? 简而言之,FlowDocumentReader 是一个提供查看 流内容 功能的控件。 它让用户可以选择多种查看模式。 此控件带有滚动条和搜索功能。

代码!

首先,我们将创建 DockPanel 并添加两个 TextBlock。 我们会将一个 TextBlock 停靠到 DockPanel 的顶部,以显示 Project Euler(发音为“oiler”)的徽标。 另一个 TextBlock 停靠到底部,将显示来自 Leonhard Euler 的引言。

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Sundeepan's Stack Panel Example">
<DockPanel LastChildFill="True">
<TextBlock
DockPanel.Dock="Top"
Background="White"
TextBlock.FontFamily="Verdana"
TextBlock.FontSize="48"
VerticalAlignment="Center">
<Image
Source="http://projecteuler.net/images/logo.jpg"
Width="287"
Height="67"/>
</TextBlock>
<TextBlock DockPanel.Dock="Bottom"
Background="DarkRed"
Foreground="White" 
FontSize="10">
For since the fabric of the universe is most perfect 
and the work of a most wise Creator,
nothing at all takes place in the universe in which some rule of 
maximum or minimum does not appear. 
- &#169; 1783 Euler  
</TextBlock>
</DockPanel>
</Window> 

紧接着最后一个 TextBlock,我们添加一个 StackPanel 并将其停靠到 DockPanel 的左侧。 在新添加的 StackPanel 内部,我们放置一张 Leonhard Euler 的图像。 请参阅下面的代码

<StackPanel
    DockPanel.Dock="Left"
    VerticalAlignment="Center"
    Margin="5">
    <Image
        Source="http://www.pas.rochester.edu/~cline/P235W/Leonhard_Euler_2.jpg"
        Height="223"
        Width="180"/>
</StackPanel>  

现在,我们将 FlowDocumentReader 作为 DockPanel 中的最后一个元素添加。 还记得上一篇文章 使用 XAML 创建 WPF DockPanel 吗? 如果 LastChildFill="True",则添加的最后一个子元素将填充其他子元素未占据的空间(这个子元素相当贪婪!)。 在这种情况下,FlowDocumentReader 将是最后一个子元素,它将占据剩余的空间。 请参阅下面的代码

 <FlowDocumentReader>
    <FlowDocument>
        <Paragraph>
            <Bold></Bold>
        </Paragraph>
        <Paragraph>
            <Paragraph.FontFamily>Verdana</Paragraph.FontFamily>
            <Paragraph.FontSize>36</Paragraph.FontSize>
            <Bold>About Project Euler</Bold>
        </Paragraph>
        <Paragraph>
            <Paragraph.FontFamily>Verdana</Paragraph.FontFamily>
            <Paragraph.FontSize>18</Paragraph.FontSize>
            <Bold>What is Project Euler?</Bold>
        </Paragraph>
        <Paragraph>
            Project Euler is a series of challenging mathematical/computer 
            programming problems that will require more than just mathematical 
            insights to solve. Although mathematics will help you arrive at 
            elegant and efficient methods, the use of a computer and programming skills 
            will be required to solve most problems.The motivation for starting 
            Project Euler, and its continuation, is to provide a platform for the 
            inquiring mind to delve into unfamiliar areas and learn new concepts 
            in a fun and recreational context.
        </Paragraph>
        <Paragraph>
            <Paragraph.FontFamily>Verdana</Paragraph.FontFamily>
            <Paragraph.FontSize>18</Paragraph.FontSize>
            <Bold>Who are the problems aimed at?</Bold>
        </Paragraph>
        <Paragraph>
            The intended audience include students for whom the basic curriculum 
            is not feeding their hunger to learn, adults whose background was not 
            primarily mathematics but had an interest in things mathematical, 
            and professionals who want to keep their problem solving and mathematics 
            on the edge.
        </Paragraph>
        <Paragraph>
            <Paragraph.FontFamily>Verdana</Paragraph.FontFamily>
            <Paragraph.FontSize>18</Paragraph.FontSize>
            <Bold>Can anyone solve the problems?</Bold>
        </Paragraph>                
        <Paragraph>
            The problems range in difficulty and for many the experience 
            is inductive chain learning. 
            That is, by solving one problem it will expose you to a new concept 
            that allows you to undertake a previously inaccessible problem. 
            So the determined participant will slowly but surely work his/her 
            way through every problem.
        </Paragraph>
    </FlowDocument>
 </FlowDocumentReader> 

现在您的应用程序应该看起来像上面的截图了!

历史

  • 2010 年 3 月 18 日:初始发布
© . All rights reserved.