回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,50 +1,48 @@
|
|
1
|
-
Windows Formsの[DataGridView](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datagridview)と紛らわしいので、
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
using System.
|
15
|
-
using System.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
{
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
new orgFileInfo{ FileName = "
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Debug.WriteLine("
|
42
|
-
Debug.WriteLine("
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
}
|
49
|
-
}
|
1
|
+
Windows Formsの[DataGridView](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datagridview)と紛らわしいので、[DataGrid](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.datagrid)と正しく表記してください。
|
2
|
+
|
3
|
+
> チェックボックスをチェックされた時に、対象のファイル名(DataContextで取得できる?)を取得したいが、取得できない。
|
4
|
+
|
5
|
+
1. `sender`を`CheckBox`にキャスト
|
6
|
+
1. さらに`CheckBox`の`DataContext`を`orgFileInfo`にキャスト
|
7
|
+
|
8
|
+
で取得できます。
|
9
|
+
|
10
|
+
|
11
|
+
```cs
|
12
|
+
using System.Collections.Generic;
|
13
|
+
using System.Diagnostics;
|
14
|
+
using System.Windows;
|
15
|
+
using System.Windows.Controls;
|
16
|
+
|
17
|
+
namespace Questions340821
|
18
|
+
{
|
19
|
+
public partial class MainWindow : Window
|
20
|
+
{
|
21
|
+
public MainWindow()
|
22
|
+
{
|
23
|
+
InitializeComponent();
|
24
|
+
|
25
|
+
forder1DataGrid.ItemsSource = new List<orgFileInfo>
|
26
|
+
{
|
27
|
+
new orgFileInfo{ FileName = "FileName1", Comment = "Comment1", },
|
28
|
+
new orgFileInfo{ FileName = "FileName2", Comment = "Comment2", },
|
29
|
+
new orgFileInfo{ FileName = "FileName3", Comment = "Comment3", },
|
30
|
+
};
|
31
|
+
}
|
32
|
+
|
33
|
+
private void folder1_click(object sender, RoutedEventArgs e)
|
34
|
+
{
|
35
|
+
if (sender is CheckBox checkBox)
|
36
|
+
{
|
37
|
+
if (checkBox.DataContext is orgFileInfo info)
|
38
|
+
{
|
39
|
+
Debug.WriteLine("IsChecked:" + info.IsChecked);
|
40
|
+
Debug.WriteLine("FileName:" + info.FileName);
|
41
|
+
Debug.WriteLine("Comment:" + info.Comment);
|
42
|
+
Debug.WriteLine("");
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
50
48
|
```
|