2010-11-24 6 views
1

Je souhaite imprimer une page à partir d'un texte que j'ai avec un petit en-tête. Je voulais que tout le texte soit centré sur la page mais je ne sais pas comment le faire ..WPF Impression FlowDocument non centré

Voici mon code .. t est de type piste qui est juste un objet qui contient des informations comme le nom de l'artiste , nom de l'album, titre de la chanson et paroles.

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"); 

Les impressions de pages très bien à l'exception du fait que la chose s'accroche à la gauche du document lors de l'impression ... Je sais qu'il ya une propriété, je ne suis pas la mise en définissant correctement ou pas du tout.

Répondre

0

augmentez la taille de la propriété ColumnWidth ou faites-en simplement '999999'

Questions connexes