当前位置: 移动技术网 > IT编程>开发语言>.net > [WPF 学习] 7.2 模板打印

[WPF 学习] 7.2 模板打印

2020年03月17日  | 移动技术网IT编程  | 我要评论

国庆节小报内容,703804散讲温州,小鹅与红房子

利用flowdocument进行模板打印

xaml

    <dockpanel >
        <button  content="preview"  margin="15" click="button_click_1" dockpanel.dock="bottom" height="76"/>
        <flowdocumentpageviewer verticalalignment="top" width="300" name="fd" borderbrush="blue" borderthickness="2">

            <flowdocument pagepadding="38" >
                <paragraph textalignment="center">
                    <run  fontfamily="宋体" fontweight="bold">酒店名称:</run> [hotelname]
                </paragraph>
                <blockuicontainer>
                    <line x1="0" y1="0" x2="800" y2="0" stroke="black"/>
                </blockuicontainer>
                <paragraph>
                    <run fontweight="bold">日期:</run> [date]
                </paragraph>

            </flowdocument>
        </flowdocumentpageviewer>

    </dockpanel>

代码

        private void button_click_1(object sender, routedeventargs e)
        {
            var filename = @"test.xaml";
            using (filestream fs = new filestream(filename, filemode.openorcreate))
            {
                xamlwriter.save(fd.document, fs);
            }

            var sts = file.readalltext(filename);
            sts = sts.replace("[hotelname]", "naradahotel")
                   .replace("[date]", datetime.now.tolongdatestring());

            var d = ((idocumentpaginatorsource)xamlreader.parse(sts)).documentpaginator;
            printdialog pd = new printdialog();
            pd.printdocument(d, "test");


        }

用string.replace进行替换,不知道也没有其他办法?

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网