将FlowDocument添加到MainWindow

时间:2013-08-08 16:31:48

标签: c# flowdocument

将保存为Xaml的FlowDocument添加到应用程序的主窗口的最佳做法是什么。

<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <FlowDocumentReader Document="">
            <FlowDocument>
                <!-- I WANT TO ADD THE FLOWDOCUMENT I SAVED AS AN XAML HERE-->
            </FlowDocument>
        </FlowDocumentReader>
    </Grid>
</Window>

感谢。

1 个答案:

答案 0 :(得分:2)

我使用了此页面上的示例。

http://msdn.microsoft.com/en-us/library/ms751864(v=vs.85).aspx

Xaml代码

<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20"></RowDefinition>
            <RowDefinition Height="100*"></RowDefinition>
        </Grid.RowDefinitions>
        <Button Name="PrintSimpleTextButton" Content="Print Button" Width="100" Grid.Row="0" Click="PrintSimpleTextButton_Click"></Button>

        <FlowDocumentReader
            Name="flowDocRdr" 
            IsFindEnabled="True"  
            IsPrintEnabled="True"
            MinZoom="50" MaxZoom="1000"
            Zoom="100" ZoomIncrement="5"
            Grid.Row="1"
        />

    </Grid>
</Window>

加载flowdocument的代码

private void PrintSimpleTextButton_Click(object sender, RoutedEventArgs e)
{
     string filename = "C:\\Users\\Me\\Dropbox\\Engineering\\Practice\\C# Xaml\\PrinterTest\\PrinterTest\\QRCodeStyleA_FlowDoc.xaml";
            FileStream xamlFile = new FileStream(filename, FileMode.Open, FileAccess.Read);
            FlowDocument content = System.Windows.Markup.XamlReader.Load(xamlFile) as FlowDocument;
            flowDocRdr.Document = content;


        }