回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,321 +1,162 @@
|
|
1
1
|
**ヘッダーのリサイズや入れ替えをさせない**のであれば、Grid等で偽のヘッダーをでっちあげます。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
できるだけ画像に寄せましたが、こんな感じでどうでしょうか?
|
6
|
-
|
7
|
-
```x
|
4
|
+
```xml
|
8
|
-
|
9
5
|
<Window
|
10
|
-
|
11
6
|
x:Class="Questions306366.MainWindow"
|
12
|
-
|
13
7
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
14
|
-
|
15
8
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
16
|
-
|
17
9
|
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
|
18
|
-
|
19
10
|
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
20
|
-
|
21
11
|
Width="800"
|
22
|
-
|
23
12
|
Height="450">
|
24
|
-
|
25
13
|
<Window.Resources>
|
26
|
-
|
27
14
|
<!-- 特に意味はない xamlのみ縛り -->
|
28
|
-
|
29
15
|
<collections:ArrayList x:Key="data">
|
30
|
-
|
31
16
|
<collections:ArrayList>
|
32
|
-
|
33
17
|
<sys:Int32>1</sys:Int32>
|
34
|
-
|
35
18
|
<sys:String>一郎</sys:String>
|
36
|
-
|
37
19
|
<sys:DateTime>1998-01-01</sys:DateTime>
|
38
|
-
|
39
20
|
<sys:Int32>22</sys:Int32>
|
40
|
-
|
41
21
|
<sys:String>あ</sys:String>
|
42
|
-
|
43
22
|
<sys:String>い</sys:String>
|
44
|
-
|
45
23
|
<sys:String>う</sys:String>
|
46
|
-
|
47
24
|
<sys:String>え</sys:String>
|
48
|
-
|
49
25
|
</collections:ArrayList>
|
50
|
-
|
51
26
|
<collections:ArrayList>
|
52
|
-
|
53
27
|
<sys:Int32>2</sys:Int32>
|
54
|
-
|
55
28
|
<sys:String>次郎</sys:String>
|
56
|
-
|
57
29
|
<sys:DateTime>1999-02-02</sys:DateTime>
|
58
|
-
|
59
30
|
<sys:Int32>21</sys:Int32>
|
60
|
-
|
61
31
|
<sys:String>お</sys:String>
|
62
|
-
|
63
32
|
<sys:String>か</sys:String>
|
64
|
-
|
65
33
|
<sys:String>き</sys:String>
|
66
|
-
|
67
34
|
<sys:String>く</sys:String>
|
68
|
-
|
69
35
|
</collections:ArrayList>
|
70
|
-
|
71
36
|
</collections:ArrayList>
|
72
37
|
|
73
|
-
|
74
|
-
|
75
38
|
<Style TargetType="DataGridColumnHeader">
|
76
|
-
|
77
39
|
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
78
|
-
|
79
40
|
</Style>
|
80
|
-
|
81
41
|
<Style x:Key="CellStyleRight" TargetType="DataGridCell">
|
82
|
-
|
83
42
|
<Setter Property="TextBlock.TextAlignment" Value="Right" />
|
84
|
-
|
85
43
|
</Style>
|
86
|
-
|
87
44
|
</Window.Resources>
|
88
45
|
|
89
|
-
|
90
|
-
|
91
46
|
<Grid>
|
92
|
-
|
93
47
|
<DockPanel>
|
94
|
-
|
95
48
|
<!-- 偽ヘッダー -->
|
96
|
-
|
97
49
|
<Grid
|
98
|
-
|
99
50
|
Margin="1,1,1,0"
|
100
|
-
|
101
51
|
Cursor="Arrow"
|
102
|
-
|
103
52
|
DockPanel.Dock="Top"
|
104
|
-
|
105
53
|
ForceCursor="True">
|
106
|
-
|
107
54
|
<Grid.ColumnDefinitions>
|
108
|
-
|
109
55
|
<ColumnDefinition Width="Auto" />
|
110
|
-
|
111
56
|
<ColumnDefinition Width="Auto" />
|
112
|
-
|
113
57
|
<ColumnDefinition Width="Auto" />
|
114
|
-
|
115
58
|
<ColumnDefinition Width="Auto" />
|
116
|
-
|
117
59
|
<ColumnDefinition Width="Auto" />
|
118
|
-
|
119
60
|
<ColumnDefinition Width="Auto" />
|
120
|
-
|
121
61
|
<ColumnDefinition Width="Auto" />
|
122
|
-
|
123
62
|
<ColumnDefinition Width="Auto" />
|
124
|
-
|
125
63
|
<ColumnDefinition />
|
126
|
-
|
127
64
|
</Grid.ColumnDefinitions>
|
128
|
-
|
129
65
|
<Grid.RowDefinitions>
|
130
|
-
|
131
66
|
<RowDefinition />
|
132
|
-
|
133
67
|
<RowDefinition />
|
134
|
-
|
135
68
|
<RowDefinition />
|
136
|
-
|
137
69
|
</Grid.RowDefinitions>
|
138
|
-
|
139
70
|
<DataGridColumnHeader Grid.RowSpan="3" Width="{Binding ActualWidth, ElementName=NumberColumn}" Content="番号" />
|
140
|
-
|
141
71
|
<DataGridColumnHeader
|
142
|
-
|
143
72
|
Grid.Row="1"
|
144
|
-
|
145
73
|
Grid.RowSpan="2"
|
146
|
-
|
147
74
|
Grid.Column="1"
|
148
|
-
|
149
75
|
Width="{Binding ActualWidth, ElementName=NameColumn}"
|
150
|
-
|
151
76
|
Content="名前" />
|
152
|
-
|
153
77
|
<DataGridColumnHeader
|
154
|
-
|
155
78
|
Grid.Row="1"
|
156
|
-
|
157
79
|
Grid.RowSpan="2"
|
158
|
-
|
159
80
|
Grid.Column="2"
|
160
|
-
|
161
81
|
Width="{Binding ActualWidth, ElementName=DOBColumn}"
|
162
|
-
|
163
82
|
Content="生年月日" />
|
164
|
-
|
165
83
|
<DataGridColumnHeader
|
166
|
-
|
167
84
|
Grid.Row="1"
|
168
|
-
|
169
85
|
Grid.RowSpan="2"
|
170
|
-
|
171
86
|
Grid.Column="3"
|
172
|
-
|
173
87
|
Width="{Binding ActualWidth, ElementName=AgeColumn}"
|
174
|
-
|
175
88
|
Content="年齢" />
|
176
|
-
|
177
89
|
<DataGridColumnHeader
|
178
|
-
|
179
90
|
Grid.Row="2"
|
180
|
-
|
181
91
|
Grid.Column="4"
|
182
|
-
|
183
92
|
Width="{Binding ActualWidth, ElementName=DDDDColumn}"
|
184
|
-
|
185
93
|
Content="DDDD" />
|
186
|
-
|
187
94
|
<DataGridColumnHeader
|
188
|
-
|
189
95
|
Grid.Row="2"
|
190
|
-
|
191
96
|
Grid.Column="5"
|
192
|
-
|
193
97
|
Width="{Binding ActualWidth, ElementName=EEEEColumn}"
|
194
|
-
|
195
98
|
Content="EEEE" />
|
196
|
-
|
197
99
|
<DataGridColumnHeader
|
198
|
-
|
199
100
|
Grid.Row="2"
|
200
|
-
|
201
101
|
Grid.Column="6"
|
202
|
-
|
203
102
|
Width="{Binding ActualWidth, ElementName=FFFFColumn}"
|
204
|
-
|
205
103
|
Content="FFFF" />
|
206
|
-
|
207
104
|
<DataGridColumnHeader
|
208
|
-
|
209
105
|
Grid.Row="2"
|
210
|
-
|
211
106
|
Grid.Column="7"
|
212
|
-
|
213
107
|
Width="{Binding ActualWidth, ElementName=GGGGColumn}"
|
214
|
-
|
215
108
|
Content="GGGG" />
|
216
109
|
|
217
|
-
|
218
|
-
|
219
110
|
<DataGridColumnHeader Grid.Column="1" Grid.ColumnSpan="3" Content="個人情報" />
|
220
|
-
|
221
111
|
<DataGridColumnHeader Grid.Column="4" Grid.ColumnSpan="4" Content="AAAA" />
|
222
|
-
|
223
112
|
<DataGridColumnHeader
|
224
|
-
|
225
113
|
Grid.Row="1"
|
226
|
-
|
227
114
|
Grid.Column="4"
|
228
|
-
|
229
115
|
Grid.ColumnSpan="2"
|
230
|
-
|
231
116
|
Content="BBBB" />
|
232
|
-
|
233
117
|
<DataGridColumnHeader
|
234
|
-
|
235
118
|
Grid.Row="1"
|
236
|
-
|
237
119
|
Grid.Column="6"
|
238
|
-
|
239
120
|
Grid.ColumnSpan="2"
|
240
|
-
|
241
121
|
Content="CCCC" />
|
242
|
-
|
243
122
|
<Border />
|
244
|
-
|
245
123
|
</Grid>
|
246
124
|
|
247
|
-
|
248
|
-
|
249
125
|
<DataGrid AutoGenerateColumns="False" HeadersVisibility="None" ItemsSource="{StaticResource data}">
|
250
|
-
|
251
126
|
<DataGrid.Columns>
|
252
|
-
|
253
127
|
<DataGridTextColumn
|
254
|
-
|
255
128
|
x:Name="NumberColumn"
|
256
|
-
|
257
129
|
Width="90"
|
258
|
-
|
259
130
|
Binding="{Binding [0]}"
|
260
|
-
|
261
131
|
CellStyle="{StaticResource CellStyleRight}" />
|
262
|
-
|
263
132
|
<DataGridTextColumn x:Name="NameColumn" Width="90" Binding="{Binding [1]}" />
|
264
|
-
|
265
133
|
<DataGridTextColumn
|
266
|
-
|
267
134
|
x:Name="DOBColumn"
|
268
|
-
|
269
135
|
Width="90"
|
270
|
-
|
271
136
|
Binding="{Binding [2], StringFormat=M月d日}"
|
272
|
-
|
273
137
|
CellStyle="{StaticResource CellStyleRight}" />
|
274
|
-
|
275
138
|
<DataGridTextColumn
|
276
|
-
|
277
139
|
x:Name="AgeColumn"
|
278
|
-
|
279
140
|
Width="90"
|
280
|
-
|
281
141
|
Binding="{Binding [3]}"
|
282
|
-
|
283
142
|
CellStyle="{StaticResource CellStyleRight}" />
|
284
|
-
|
285
143
|
<DataGridTextColumn x:Name="DDDDColumn" Width="90" Binding="{Binding [4]}" />
|
286
|
-
|
287
144
|
<DataGridTextColumn x:Name="EEEEColumn" Width="90" Binding="{Binding [5]}" />
|
288
|
-
|
289
145
|
<DataGridTextColumn x:Name="FFFFColumn" Width="90" Binding="{Binding [6]}" />
|
290
|
-
|
291
146
|
<DataGridTextColumn x:Name="GGGGColumn" Width="90" Binding="{Binding [7]}" />
|
292
|
-
|
293
147
|
</DataGrid.Columns>
|
294
|
-
|
295
148
|
</DataGrid>
|
296
|
-
|
297
149
|
</DockPanel>
|
298
|
-
|
299
150
|
</Grid>
|
300
|
-
|
301
151
|
</Window>
|
302
|
-
|
303
152
|
```
|
304
|
-
|
305
153
|
![アプリ画像](0613f71464a2f2f8f29d43db2bae3a2a.png)
|
306
|
-
|
307
|
-
|
308
154
|
|
309
155
|
ソート機能を生かすには`DataGridColumnHeader`の`Click`を拾い、ソースのソートをしてください。
|
310
156
|
|
311
|
-
|
312
|
-
|
313
|
-
小さい`へ`の字を出すには、
|
157
|
+
小さい`へ`の字を出すには、↓は`set`がないのでいじれませんが、
|
314
|
-
|
315
158
|
[DataGridColumnHeader.SortDirection プロパティ (System.Windows.Controls.Primitives) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.primitives.datagridcolumnheader.sortdirection?view=net-5.0#System_Windows_Controls_Primitives_DataGridColumnHeader_SortDirection)
|
316
159
|
|
317
|
-
|
160
|
+
`DataGridColumnHeader`の子孫にいるこちらをいじれば表示されました。
|
318
|
-
|
319
161
|
[DataGridHeaderBorder.SortDirection プロパティ (Microsoft.Windows.Themes) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/microsoft.windows.themes.datagridheaderborder.sortdirection?view=net-5.0#Microsoft_Windows_Themes_DataGridHeaderBorder_SortDirection)
|
320
162
|
|
321
|
-
`DataGridColumnHeader`の子孫にいるこちらをいじれば表示されました。
|