【问题标题】:WPF Printing FlowDocument not centeringWPF打印FlowDocument不居中
【发布时间】:2011-05-14 20:59:08
【问题描述】:

我想从我拥有的一些带有小标题的文本中打印一个页面。 我希望所有文本都集中在页面上,但我不知道该怎么做..

这是我的代码.. t 是 track 类型,它只是一个包含艺术家姓名、专辑名称、歌曲标题和歌词等信息的对象。

 PrintDialog dialog = new PrintDialog();
            if (dialog.ShowDialog() != true)
            { return; }
            FlowDocument doc = new FlowDocument();
            Section sec = new Section();
            Paragraph header = new Paragraph();
            Paragraph body = new Paragraph();
            Bold boldSong = new Bold();
            boldSong.Inlines.Add(new Run(t.Song));
            header.Inlines.Add(boldSong);
            header.Inlines.Add(new LineBreak());
            Bold boldArtist = new Bold();
            if (!string.IsNullOrWhiteSpace(t.Artist))
            {
                boldArtist.Inlines.Add(new Run(t.Artist));
                header.Inlines.Add(boldArtist);
                header.Inlines.Add(new LineBreak());
            }
            Bold boldAlbum = new Bold();
            if (!string.IsNullOrWhiteSpace(t.Album))
            {
                boldAlbum.Inlines.Add(new Run(t.Album));
                header.Inlines.Add(boldAlbum);
                header.Inlines.Add(new LineBreak());
            }
            header.TextAlignment = TextAlignment.Center;
            body.Inlines.Add(t.iTunesFileTrack.Lyrics);
            body.TextAlignment = TextAlignment.Center;
            doc.Blocks.Add(header);
            doc.Blocks.Add(body);
            doc.Name = "FlowDoc";
            IDocumentPaginatorSource idpSource = doc;
            DocumentPaginator holder = idpSource.DocumentPaginator;
            holder.PageSize = new Size(dialog.PrintableAreaWidth,
        dialog.PrintableAreaHeight);
            dialog.PrintDocument(holder, "Lyrics");

页面打印得很好,除了打印时整个东西都紧贴在文档的左侧......我知道有一些属性我没有正确设置或根本没有设置..

【问题讨论】:

    标签: wpf printing alignment center flowdocument


    【解决方案1】:

    增加 ColumnWidth 属性的大小或将其设为 '999999'

    【讨论】:

      猜你喜欢
      • 2010-09-25
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      相关资源
      最近更新 更多