回答編集履歴

2

見直しキャンペーン中

2023/07/26 13:47

投稿

TN8001
TN8001

スコア9855

test CHANGED
@@ -1,153 +1,77 @@
1
1
  どこで改ページしたいのかが伝わりませんが、次ページに送りたいブロック要素の`BreakPageBefore`を`true`にすればいいんじゃないでしょうか。
2
-
3
-
4
2
 
5
3
  [Block.BreakPageBefore プロパティ (System.Windows.Documents) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.documents.block.breakpagebefore#System_Windows_Documents_Block_BreakPageBefore)
6
4
 
7
-
8
-
9
- ```xaml
5
+ ```xml
10
-
11
6
  <FlowDocument>
12
-
13
7
  <Paragraph Background="Beige" FontFamily="Georgia">
14
-
15
8
  <TextBlock Height="70" Text="{Binding Shindan}" />
16
-
17
9
  </Paragraph>
18
10
 
19
-
20
-
21
11
  <Paragraph
22
-
23
12
  Background="Bisque"
24
-
25
13
  BreakPageBefore="True"
26
-
27
14
  FontFamily="Georgia">
28
-
29
15
  <TextBlock Height="120" Text="{Binding Shoken}" />
30
-
31
16
  </Paragraph>
32
-
33
17
  </FlowDocument>
34
-
35
18
  ```
36
-
37
-
38
19
 
39
20
  ---
40
21
 
41
-
42
-
43
22
  追記 コードビハインド
44
-
45
- ```C#
23
+ ```cs
46
-
47
24
  using System.Collections.Generic;
48
-
49
25
  using System.Windows;
50
-
51
26
  using System.Windows.Documents;
52
27
 
53
-
54
-
55
28
  namespace Questions320442
56
-
57
29
  {
58
-
59
30
  public partial class MainWindow : Window
60
-
61
31
  {
62
-
63
32
  private Model Model;
64
33
 
65
-
66
-
67
34
  public MainWindow()
68
-
69
35
  {
70
-
71
36
  InitializeComponent();
72
37
 
73
-
74
-
75
38
  Model = new Model
76
-
77
39
  {
78
-
79
40
  _report = new List<Report>
80
-
81
41
  {
82
-
83
42
  new Report { データ1 = "page1", データ2 = "hogehoge", },
84
-
85
43
  new Report { データ1 = "page2", データ2 = "fugafuga", },
86
-
87
44
  // もちろん内容が長ければ途中で改ページが入るのでずれます
88
-
89
45
  new Report { データ1 = "page3", データ2 = "piyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\n", },
90
-
91
46
  }
92
-
93
47
  };
94
48
 
95
-
96
-
97
49
  var flowDocument = new FlowDocument();
98
-
99
50
  foreach (var txt in Model._report)
100
-
101
51
  {
102
-
103
52
  // Paragraphもブロック要素
104
-
105
53
  var paragraph = new Paragraph { FontSize = 16, BreakPageBefore = true, };
106
-
107
54
  paragraph.Inlines.Add(txt.データ1);
108
-
109
-
110
55
 
111
56
  paragraph.Inlines.Add(new LineBreak());
112
57
 
113
-
114
-
115
58
  paragraph.Inlines.Add(txt.データ2);
116
-
117
59
  flowDocument.Blocks.Add(paragraph);
118
-
119
60
  }
120
61
 
121
-
122
-
123
62
  flowDoc.Document = flowDocument;
124
-
125
63
  }
126
-
127
64
  }
128
65
 
129
-
130
-
131
66
  class Model
132
-
133
67
  {
134
-
135
68
  public IEnumerable<Report> _report;
136
-
137
69
  }
138
70
 
139
-
140
-
141
71
  class Report
142
-
143
72
  {
144
-
145
73
  public string データ1;
146
-
147
74
  public string データ2;
148
-
149
75
  }
150
-
151
76
  }
152
-
153
77
  ```

1

追記 コードビハインド

2021/02/05 03:49

投稿

TN8001
TN8001

スコア9855

test CHANGED
@@ -33,3 +33,121 @@
33
33
  </FlowDocument>
34
34
 
35
35
  ```
36
+
37
+
38
+
39
+ ---
40
+
41
+
42
+
43
+ 追記 コードビハインド
44
+
45
+ ```C#
46
+
47
+ using System.Collections.Generic;
48
+
49
+ using System.Windows;
50
+
51
+ using System.Windows.Documents;
52
+
53
+
54
+
55
+ namespace Questions320442
56
+
57
+ {
58
+
59
+ public partial class MainWindow : Window
60
+
61
+ {
62
+
63
+ private Model Model;
64
+
65
+
66
+
67
+ public MainWindow()
68
+
69
+ {
70
+
71
+ InitializeComponent();
72
+
73
+
74
+
75
+ Model = new Model
76
+
77
+ {
78
+
79
+ _report = new List<Report>
80
+
81
+ {
82
+
83
+ new Report { データ1 = "page1", データ2 = "hogehoge", },
84
+
85
+ new Report { データ1 = "page2", データ2 = "fugafuga", },
86
+
87
+ // もちろん内容が長ければ途中で改ページが入るのでずれます
88
+
89
+ new Report { データ1 = "page3", データ2 = "piyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\npiyo\n", },
90
+
91
+ }
92
+
93
+ };
94
+
95
+
96
+
97
+ var flowDocument = new FlowDocument();
98
+
99
+ foreach (var txt in Model._report)
100
+
101
+ {
102
+
103
+ // Paragraphもブロック要素
104
+
105
+ var paragraph = new Paragraph { FontSize = 16, BreakPageBefore = true, };
106
+
107
+ paragraph.Inlines.Add(txt.データ1);
108
+
109
+
110
+
111
+ paragraph.Inlines.Add(new LineBreak());
112
+
113
+
114
+
115
+ paragraph.Inlines.Add(txt.データ2);
116
+
117
+ flowDocument.Blocks.Add(paragraph);
118
+
119
+ }
120
+
121
+
122
+
123
+ flowDoc.Document = flowDocument;
124
+
125
+ }
126
+
127
+ }
128
+
129
+
130
+
131
+ class Model
132
+
133
+ {
134
+
135
+ public IEnumerable<Report> _report;
136
+
137
+ }
138
+
139
+
140
+
141
+ class Report
142
+
143
+ {
144
+
145
+ public string データ1;
146
+
147
+ public string データ2;
148
+
149
+ }
150
+
151
+ }
152
+
153
+ ```