WPF Printing FlowDocument不居中

时间:2010-11-24 03:22:52

标签: wpf printing alignment center flowdocument

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

这是我的代码..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");

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

1 个答案:

答案 0 :(得分:0)

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