teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

ViewModel側のコードを追記

2020/02/14 05:37

投稿

Coriander
Coriander

スコア12

title CHANGED
File without changes
body CHANGED
@@ -29,4 +29,101 @@
29
29
  </DataGrid.Columns>
30
30
  </DataGrid>
31
31
 
32
+ ```
33
+
34
+
35
+ ViewModel
36
+ ```ここに言語を入力
37
+
38
+ using System;
39
+ using System.Collections.Generic;
40
+ using System.Linq;
41
+ using System.Text;
42
+ using System.ComponentModel;
43
+
44
+ using Livet;
45
+ using Livet.Commands;
46
+ using Livet.Messaging;
47
+ using Livet.Messaging.IO;
48
+ using Livet.EventListeners;
49
+ using Livet.Messaging.Windows;
50
+ using System.Collections.ObjectModel;
51
+
52
+ namespace InspectDataGrid.ViewModels
53
+ {
54
+ public class MainWindowViewModel : ViewModel
55
+ {
56
+
57
+ private ObservableCollection<Item> items;
58
+ public ObservableCollection<Item> Items
59
+ {
60
+ get { return items; }
61
+ set
62
+ {
63
+ items = value;
64
+ RaisePropertyChanged();
65
+ }
66
+ }
67
+
68
+ private bool isEdit;
69
+ public bool IsEdit
70
+ {
71
+ get { return isEdit; }
72
+ set
73
+ {
74
+ isEdit = value;
75
+ RaisePropertyChanged();
76
+ }
77
+ }
78
+
79
+ private ViewModelCommand settruecommand;
80
+ public ViewModelCommand SetTrueCommand
81
+ {
82
+ get
83
+ {
84
+ if (settruecommand ==null)
85
+ {
86
+ settruecommand = new ViewModelCommand(this.SetTrue);
87
+ }
88
+ return settruecommand;
89
+ }
90
+ }
91
+
92
+ private ViewModelCommand setfalsecommand;
93
+ public ViewModelCommand SetFalseCommand
94
+ {
95
+ get
96
+ {
97
+ if (setfalsecommand ==null)
98
+ {
99
+ setfalsecommand = new ViewModelCommand(this.SetFalse);
100
+ }
101
+ return setfalsecommand;
102
+ }
103
+ }
104
+
105
+
106
+ public MainWindowViewModel()
107
+ {
108
+ this.Items = new ObservableCollection<Item>();
109
+ this.Items.Add(new Item("a", 24));
110
+ this.Items.Add(new Item("b", 25));
111
+
112
+ }
113
+ public void Initialize()
114
+ {
115
+ }
116
+
117
+ public void SetTrue()
118
+ {
119
+ this.IsEdit = true;
120
+ }
121
+
122
+ public void SetFalse()
123
+ {
124
+ this.IsEdit = false;
125
+ }
126
+ }
127
+
128
+
32
129
  ```

2

質問文追記

2020/02/14 05:37

投稿

Coriander
Coriander

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,8 +1,11 @@
1
1
  初歩的な質問になりますが、DataGridTextColumnのCellStyleに対してViewModelのプロパティでDataTriggerを仕掛けても期待通りの動作となりませんでした。
2
2
  詳細としては、以下の通りシンプルなViewにbool型のIsEditプロパティを指定し、ViewModel側でTrue/Falseを切り替えてもBorderBrushに変化がありませんでした。IsEditをDataGrid以外のほかの要素に同様にStyle Triggerを指定すると正しく動作するのでbindは問題なさそうです。
3
3
 
4
- bool型プロパティ指定した場合、何が不足しているのでしょうか?
4
+ 一方、ItemSourceとしてバインドしているItemsコレクションのAgeプロパティをDataTriggerとしてBindingに指定しValueへ任意数値を指定し、DataGrid上その数値を入力するとStyleは正く適用されます。
5
5
 
6
+
7
+ bool型プロパティで指定した場合、なぜTriggerは動作しないのでしょうか?
8
+
6
9
  View
7
10
  ```ここに言語を入力
8
11
  <DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">

1

質問文修正

2020/02/14 04:32

投稿

Coriander
Coriander

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,8 @@
1
1
  初歩的な質問になりますが、DataGridTextColumnのCellStyleに対してViewModelのプロパティでDataTriggerを仕掛けても期待通りの動作となりませんでした。
2
- 詳細としては、以下の通りシンプルなViewにbool型のIsEditプロパティを指定し、ViewModel側でTrue/Falseを切り替えてもBorderBrushに変化がありませんでした。IsEditをDataGrid以外のほ
2
+ 詳細としては、以下の通りシンプルなViewにbool型のIsEditプロパティを指定し、ViewModel側でTrue/Falseを切り替えてもBorderBrushに変化がありませんでした。IsEditをDataGrid以外のほかの要素に同様にStyle Triggerを指定すると正しく動作するのでbindは問題なさそうです。
3
3
 
4
+ bool型プロパティで指定した場合、何が不足しているのでしょうか?
5
+
4
6
  View
5
7
  ```ここに言語を入力
6
8
  <DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">