回答編集履歴

1

見直しキャンペーン中

2023/07/28 17:03

投稿

TN8001
TN8001

スコア9801

test CHANGED
@@ -1,149 +1,75 @@
1
1
  C#コード側から`DataInfo`のプロパティを変更する場合は、`DataInfo`に`INotifyPropertyChanged`を実装してください。
2
2
 
3
-
4
-
5
3
  WPFにおいて`INotifyPropertyChanged`は最重要インターフェースです。
6
-
7
4
  [INotifyPropertyChanged インターフェイス (System.ComponentModel) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.componentmodel.inotifypropertychanged)
8
-
9
-
10
5
 
11
6
  `vmDataInfo`の`get`・`set`でやっていることを、`SelectIndex`でもやるということです(逆に`vmDataInfo`でやる意味はないです)
12
7
 
13
-
14
-
15
- ```C#
8
+ ```cs
16
-
17
9
  using Livet;
18
-
19
10
  using System.Collections.ObjectModel;
20
11
 
21
-
22
-
23
12
  namespace Questions355938.ViewModels
24
-
25
13
  {
26
-
27
14
  public class DataInfo : ViewModel
28
-
29
15
  {
30
-
31
16
  private string _SelectIndex;
32
-
33
17
  public string SelectIndex
34
-
35
18
  {
36
-
37
19
  get => _SelectIndex;
38
-
39
20
  set
40
-
41
21
  {
42
-
43
22
  //if (_SelectIndex != value)
44
-
45
23
  //{
46
-
47
24
  // _SelectIndex = value;
48
-
49
25
  // RaisePropertyChanged();
50
-
51
26
  //}
52
-
53
27
  // ↑の短縮形
54
-
55
28
  RaisePropertyChangedIfSet(ref _SelectIndex, value);
56
-
57
29
  }
58
-
59
30
  }
60
31
 
61
-
62
-
63
32
  public string ParamName { get; set; }
64
-
65
33
  public int Param1 { get; set; }
66
-
67
34
  public int Param2 { get; set; }
68
-
69
35
  }
70
36
 
71
-
72
-
73
37
  class MainWindowVM : ViewModel
74
-
75
38
  {
76
-
77
39
  public ObservableCollection<DataInfo> vmDataInfo { get; }
78
40
 
79
-
80
-
81
41
  public MainWindowVM()
82
-
83
42
  {
84
-
85
43
  vmDataInfo = new ObservableCollection<DataInfo>
86
-
87
44
  {
88
-
89
45
  new DataInfo { ParamName = "Parameter 1", Param1 = 100, Param2 = 0 },
90
-
91
46
  new DataInfo { ParamName = "Parameter 2", Param1 = 200, Param2 = 99 },
92
-
93
47
  new DataInfo { ParamName = "Parameter 3", Param1 = 300, Param2 = 199 },
94
-
95
48
  new DataInfo { ParamName = "Parameter 4", Param1 = 400, Param2 = 299 },
96
-
97
49
  new DataInfo { ParamName = "Parameter 5", Param1 = 500, Param2 = 399 },
98
-
99
50
  };
100
-
101
51
  }
102
52
 
103
-
104
-
105
53
  public void CurrentCellChanged(object sender)
106
-
107
54
  {
108
-
109
55
  if (sender is DataInfo info)
110
-
111
56
  {
112
-
113
57
  var selectIndex = 0;
114
-
115
58
  foreach (var data in vmDataInfo)
116
-
117
59
  {
118
-
119
60
  if (info.ParamName == data.ParamName)
120
-
121
61
  {
122
-
123
62
  vmDataInfo[selectIndex].SelectIndex = "●";
124
-
63
+ }
64
+ else
65
+ {
66
+ vmDataInfo[selectIndex].SelectIndex = "";
125
67
  }
126
68
 
127
- else
128
-
129
- {
130
-
131
- vmDataInfo[selectIndex].SelectIndex = "";
132
-
133
- }
134
-
135
-
136
-
137
69
  selectIndex++;
138
-
139
70
  }
140
-
141
71
  }
142
-
143
72
  }
144
-
145
73
  }
146
-
147
74
  }
148
-
149
75
  ```