2 つのドキュメントを印刷する必要がある印刷ボタンがあります。これどうやってするの?
手紙は私のページのテキストボックスの中にあります。
これが私のコードです:
void btPrint_Click(object sender, RoutedEventArgs e)
        {
            if (itmCandidatSelect.LettreMotiv != null || itmCandidatSelect.LettreMotiv != "")
            {
                _lineIndex = 0;
                _documentBodyLines = new List<string>();
                string[] lines = tbLettreMotiv.Text.Split(new char[] { '\r' }, StringSplitOptions.None);
                _documentBodyLines.AddRange(lines);
                PrintDocument maLettreMotiv = new PrintDocument();
                //maLettreMotiv.BeginPrint += new EventHandler<BeginPrintEventArgs>(maLettreMotiv_BeginPrint);
                //maLettreMotiv.EndPrint += new EventHandler<EndPrintEventArgs>(maLettreMotiv_EndPrint);
                maLettreMotiv.PrintPage += new EventHandler<PrintPageEventArgs>(maLettreMotiv_PrintPage);
                maLettreMotiv.Print("LettreMotivation_" + itmCandidatSelect.NomCandidat + "_" + itmCandidatSelect.PrenomCandidat);
            }
}
    int _lineIndex;
        List<string> _documentBodyLines;
void maLettreMotiv_PrintPage(object sender, PrintPageEventArgs e)
        {
            PrintLettreMotivTemplate page = new PrintLettreMotivTemplate();
            page.SetHeaderAndFooterText("Lettre de motivation", "");
            int numberOfLinesAdded = 0;
            while (_lineIndex < _documentBodyLines.Count)
            {
                page.AddLine(_documentBodyLines[_lineIndex]);
                page.Measure(new Size(e.PrintableArea.Width, double.PositiveInfinity));
                if (page.DesiredSize.Height > e.PrintableArea.Height && numberOfLinesAdded > 1)
                {
                    page.RemoveLastLine();
                    e.HasMorePages = true;
                    break;
                }
                _lineIndex++;
                numberOfLinesAdded++;
            }
             e.PageVisual = page;
        }
私のテンプレート:
<UserControl x:Class="erecrutement_procclass.Views.PrintLettreMotivTemplate"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             Width="815" 
             Height="1024"
             mc:Ignorable="d"    
             d:DesignHeight="300" 
             d:DesignWidth="400">
<Grid x:Name="documentRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="25"/>
        <RowDefinition />
        <RowDefinition Height="25"/>
    </Grid.RowDefinitions>
    <TextBlock x:Name="headerTextBlock" HorizontalAlignment="Center" />
    <TextBlock x:Name="bodyTextBlock" Grid.Row="1" TextWrapping="Wrap" Margin="5,5,5,5"/>
    <TextBlock x:Name="footerTextBlock" HorizontalAlignment="Center" Grid.Row="2"/>
</Grid>
 public partial class PrintLettreMotivTemplate : UserControl
    {
        public PrintLettreMotivTemplate()
        {
            InitializeComponent();
        }
        public void SetHeaderAndFooterText(string header, string footer)
        {
            headerTextBlock.Text = header;
            footerTextBlock.Text = footer;
        }
        public void AddLine(string line)
        {
            bodyTextBlock.Inlines.Add(line);
            bodyTextBlock.Inlines.Add(new LineBreak());
        }
        public void RemoveLastLine()
        {
            for (int index = 0; index < 2; index++)
            {
                bodyTextBlock.Inlines.RemoveAt(bodyTextBlock.Inlines.Count - 1);
            }
        }
    }
が、 万一1ページを超えたところで止まってしまい、1ページしか持たず、文字の一部が欠けてしまいました。
どうすればこれを修正できますか?
ありがとうございました。