回答編集履歴
2
見直しキャンペーン中
answer
CHANGED
@@ -1,211 +1,211 @@
|
|
1
|
-
> 色々見ているとTemplateを書き換えなければならない??
|
2
|
-
|
3
|
-
ほかの方法もあるかもしれませんが、手間は一番少ないと思います(xamlは爆発的に増えますが^^;
|
4
|
-
|
5
|
-
仮でいいのでxamlに`ComboBox`を追加してください。
|
6
|
-
デザイナ上で`ComboBox`を右クリックし、「テンプレートの編集」-「コピーして編集」でスタイルを出力します。
|
7
|
-
出力出来たら仮の`ComboBox`はもういりません。
|
8
|
-
|
9
|
-
どこかに↓ようなスタイルが出ていると思います(微妙に差があるかもしれません)
|
10
|
-
```
|
11
|
-
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
12
|
-
<Setter Property="OverridesDefaultStyle" Value="true" />
|
13
|
-
<Setter Property="IsTabStop" Value="false" />
|
14
|
-
<Setter Property="Focusable" Value="false" />
|
15
|
-
<Setter Property="ClickMode" Value="Press" />
|
16
|
-
<Setter Property="Template">
|
17
|
-
<Setter.Value>
|
18
|
-
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
19
|
-
<Border
|
20
|
-
x:Name="templateRoot"
|
21
|
-
Background="{StaticResource ComboBox.Static.Background}"
|
22
|
-
BorderBrush="{StaticResource ComboBox.Static.Border}"
|
23
|
-
BorderThickness="{TemplateBinding BorderThickness}"
|
24
|
-
SnapsToDevicePixels="true">
|
25
|
-
```
|
26
|
-
|
27
|
-
```
|
28
|
-
Background="{StaticResource ComboBox.Static.Background}"
|
29
|
-
```
|
30
|
-
ここを
|
31
|
-
```
|
32
|
-
Background="{TemplateBinding Background}"
|
33
|
-
```
|
34
|
-
このように変更します。
|
35
|
-
|
36
|
-
`DataGridTemplateColumn`の`ComboBox`の`Style`を、
|
37
|
-
```
|
38
|
-
<Style TargetType="ComboBox" BasedOn="{StaticResource ComboBoxStyle1}">
|
39
|
-
```
|
40
|
-
のように今出力したスタイルを受け継ぐようにします。
|
41
|
-
これでおそらく`Background`の変更が反映されると思います。
|
42
|
-
|
43
|
-
---
|
44
|
-
|
45
|
-
検証コード追記
|
46
|
-
|
47
|
-
```
|
48
|
-
<Window
|
49
|
-
x:Class="Questions352305.MainWindow"
|
50
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
51
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
52
|
-
xmlns:local="clr-namespace:Questions352305"
|
53
|
-
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2"
|
54
|
-
Width="800"
|
55
|
-
Height="450">
|
56
|
-
<Window.Resources>
|
57
|
-
<x:Array x:Key="ModeToComboBoxGrps" Type="{x:Type local:ModeToComboBoxGrp}">
|
58
|
-
<local:ModeToComboBoxGrp Label="0:TOP" Value="0" />
|
59
|
-
<local:ModeToComboBoxGrp Label="1:LOW" Value="1" />
|
60
|
-
</x:Array>
|
61
|
-
|
62
|
-
<!-- いろいろ省略 -->
|
63
|
-
<!--<Style x:Key="FocusVisual" />
|
64
|
-
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF" />
|
65
|
-
<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}" />-->
|
66
|
-
|
67
|
-
<!--<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
68
|
-
<Setter Property="OverridesDefaultStyle" Value="true" />
|
69
|
-
<Setter Property="IsTabStop" Value="false" />
|
70
|
-
<Setter Property="Focusable" Value="false" />
|
71
|
-
<Setter Property="ClickMode" Value="Press" />
|
72
|
-
<Setter Property="Template">
|
73
|
-
<Setter.Value>
|
74
|
-
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
75
|
-
<Border
|
76
|
-
x:Name="templateRoot"
|
77
|
-
Background="{TemplateBinding Background}"
|
78
|
-
BorderBrush="{StaticResource ComboBox.Static.Border}"
|
79
|
-
BorderThickness="{TemplateBinding BorderThickness}"
|
80
|
-
SnapsToDevicePixels="true">-->
|
81
|
-
<!-- 以下も省略 -->
|
82
|
-
|
83
|
-
<!-- いろいろ省略 -->
|
84
|
-
<!--<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}"/>
|
85
|
-
<ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}"/>
|
86
|
-
<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}"/>-->
|
87
|
-
</Window.Resources>
|
88
|
-
<DockPanel>
|
89
|
-
<ComboBox
|
90
|
-
Background="Red"
|
91
|
-
DockPanel.Dock="Top"
|
92
|
-
Style="{DynamicResource ComboBoxStyle1}" />
|
93
|
-
<Button
|
94
|
-
Click="Button2_Click"
|
95
|
-
Content="更新"
|
96
|
-
DockPanel.Dock="Top" />
|
97
|
-
<DataGrid
|
98
|
-
AutoGenerateColumns="False"
|
99
|
-
ItemsSource="{Binding Records}"
|
100
|
-
SelectionUnit="CellOrRowHeader">
|
101
|
-
<DataGrid.Columns>
|
102
|
-
|
103
|
-
<DataGridComboBoxColumn
|
104
|
-
DisplayMemberPath="Label"
|
105
|
-
Header="ComboBoxColumn"
|
106
|
-
ItemsSource="{StaticResource ModeToComboBoxGrps}"
|
107
|
-
SelectedValueBinding="{Binding Mode}"
|
108
|
-
SelectedValuePath="Value">
|
109
|
-
<DataGridComboBoxColumn.CellStyle>
|
110
|
-
<Style TargetType="DataGridCell">
|
111
|
-
<Style.Triggers>
|
112
|
-
<DataTrigger Binding="{Binding IsModeChange}" Value="True">
|
113
|
-
<Setter Property="Background" Value="LightSalmon" />
|
114
|
-
</DataTrigger>
|
115
|
-
</Style.Triggers>
|
116
|
-
</Style>
|
117
|
-
</DataGridComboBoxColumn.CellStyle>
|
118
|
-
</DataGridComboBoxColumn>
|
119
|
-
|
120
|
-
<DataGridTemplateColumn Header="Test">
|
121
|
-
<DataGridTemplateColumn.CellTemplate>
|
122
|
-
<DataTemplate>
|
123
|
-
<ComboBox
|
124
|
-
DisplayMemberPath="Label"
|
125
|
-
ItemsSource="{StaticResource ModeToComboBoxGrps}"
|
126
|
-
SelectedValue="{Binding Mode, UpdateSourceTrigger=PropertyChanged}"
|
127
|
-
SelectedValuePath="Value">
|
128
|
-
<ComboBox.Style>
|
129
|
-
<Style BasedOn="{StaticResource ComboBoxStyle1}" TargetType="ComboBox">
|
130
|
-
<Style.Triggers>
|
131
|
-
<DataTrigger Binding="{Binding IsModeChange}" Value="True">
|
132
|
-
<Setter Property="Background" Value="LightSalmon" />
|
133
|
-
</DataTrigger>
|
134
|
-
</Style.Triggers>
|
135
|
-
</Style>
|
136
|
-
</ComboBox.Style>
|
137
|
-
</ComboBox>
|
138
|
-
</DataTemplate>
|
139
|
-
</DataGridTemplateColumn.CellTemplate>
|
140
|
-
</DataGridTemplateColumn>
|
141
|
-
</DataGrid.Columns>
|
142
|
-
</DataGrid>
|
143
|
-
</DockPanel>
|
144
|
-
</Window>
|
145
|
-
```
|
146
|
-
|
147
|
-
```
|
148
|
-
using System.Collections.Generic;
|
149
|
-
using System.ComponentModel;
|
150
|
-
using System.Runtime.CompilerServices;
|
151
|
-
using System.Windows;
|
152
|
-
|
153
|
-
namespace Questions352305
|
154
|
-
{
|
155
|
-
public class Record : Observable
|
156
|
-
{
|
157
|
-
public int Mode
|
158
|
-
{
|
159
|
-
get => _Mode;
|
160
|
-
set { if (SetProperty(ref _Mode, value)) IsModeChange = true; }
|
161
|
-
}
|
162
|
-
private int _Mode;
|
163
|
-
|
164
|
-
public bool IsModeChange { get => _IsModeChange; set => SetProperty(ref _IsModeChange, value); }
|
165
|
-
private bool _IsModeChange;
|
166
|
-
}
|
167
|
-
|
168
|
-
public class ModeToComboBoxGrp
|
169
|
-
{
|
170
|
-
public string Label { get; set; }
|
171
|
-
public int Value { get; set; }
|
172
|
-
}
|
173
|
-
|
174
|
-
public partial class MainWindow : Window
|
175
|
-
{
|
176
|
-
public List<Record> Records { get; } = new List<Record>();
|
177
|
-
|
178
|
-
public MainWindow()
|
179
|
-
{
|
180
|
-
InitializeComponent();
|
181
|
-
DataContext = this;
|
182
|
-
|
183
|
-
Records.Add(new Record());
|
184
|
-
Records.Add(new Record());
|
185
|
-
Records.Add(new Record());
|
186
|
-
}
|
187
|
-
|
188
|
-
private void Button2_Click(object sender, RoutedEventArgs e)
|
189
|
-
{
|
190
|
-
foreach (var record in Records)
|
191
|
-
{
|
192
|
-
record.IsModeChange = false;
|
193
|
-
}
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
public class Observable : INotifyPropertyChanged
|
198
|
-
{
|
199
|
-
public event PropertyChangedEventHandler PropertyChanged;
|
200
|
-
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
201
|
-
{
|
202
|
-
if (Equals(storage, value)) return false;
|
203
|
-
storage = value;
|
204
|
-
OnPropertyChanged(propertyName);
|
205
|
-
return true;
|
206
|
-
}
|
207
|
-
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
208
|
-
}
|
209
|
-
}
|
210
|
-
```
|
1
|
+
> 色々見ているとTemplateを書き換えなければならない??
|
2
|
+
|
3
|
+
ほかの方法もあるかもしれませんが、手間は一番少ないと思います(xamlは爆発的に増えますが^^;
|
4
|
+
|
5
|
+
仮でいいのでxamlに`ComboBox`を追加してください。
|
6
|
+
デザイナ上で`ComboBox`を右クリックし、「テンプレートの編集」-「コピーして編集」でスタイルを出力します。
|
7
|
+
出力出来たら仮の`ComboBox`はもういりません。
|
8
|
+
|
9
|
+
どこかに↓ようなスタイルが出ていると思います(微妙に差があるかもしれません)
|
10
|
+
```xml
|
11
|
+
<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
12
|
+
<Setter Property="OverridesDefaultStyle" Value="true" />
|
13
|
+
<Setter Property="IsTabStop" Value="false" />
|
14
|
+
<Setter Property="Focusable" Value="false" />
|
15
|
+
<Setter Property="ClickMode" Value="Press" />
|
16
|
+
<Setter Property="Template">
|
17
|
+
<Setter.Value>
|
18
|
+
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
19
|
+
<Border
|
20
|
+
x:Name="templateRoot"
|
21
|
+
Background="{StaticResource ComboBox.Static.Background}"
|
22
|
+
BorderBrush="{StaticResource ComboBox.Static.Border}"
|
23
|
+
BorderThickness="{TemplateBinding BorderThickness}"
|
24
|
+
SnapsToDevicePixels="true">
|
25
|
+
```
|
26
|
+
|
27
|
+
```xml
|
28
|
+
Background="{StaticResource ComboBox.Static.Background}"
|
29
|
+
```
|
30
|
+
ここを
|
31
|
+
```xml
|
32
|
+
Background="{TemplateBinding Background}"
|
33
|
+
```
|
34
|
+
このように変更します。
|
35
|
+
|
36
|
+
`DataGridTemplateColumn`の`ComboBox`の`Style`を、
|
37
|
+
```xml
|
38
|
+
<Style TargetType="ComboBox" BasedOn="{StaticResource ComboBoxStyle1}">
|
39
|
+
```
|
40
|
+
のように今出力したスタイルを受け継ぐようにします。
|
41
|
+
これでおそらく`Background`の変更が反映されると思います。
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
検証コード追記
|
46
|
+
|
47
|
+
```xml
|
48
|
+
<Window
|
49
|
+
x:Class="Questions352305.MainWindow"
|
50
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
51
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
52
|
+
xmlns:local="clr-namespace:Questions352305"
|
53
|
+
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2"
|
54
|
+
Width="800"
|
55
|
+
Height="450">
|
56
|
+
<Window.Resources>
|
57
|
+
<x:Array x:Key="ModeToComboBoxGrps" Type="{x:Type local:ModeToComboBoxGrp}">
|
58
|
+
<local:ModeToComboBoxGrp Label="0:TOP" Value="0" />
|
59
|
+
<local:ModeToComboBoxGrp Label="1:LOW" Value="1" />
|
60
|
+
</x:Array>
|
61
|
+
|
62
|
+
<!-- いろいろ省略 -->
|
63
|
+
<!--<Style x:Key="FocusVisual" />
|
64
|
+
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF" />
|
65
|
+
<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}" />-->
|
66
|
+
|
67
|
+
<!--<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
68
|
+
<Setter Property="OverridesDefaultStyle" Value="true" />
|
69
|
+
<Setter Property="IsTabStop" Value="false" />
|
70
|
+
<Setter Property="Focusable" Value="false" />
|
71
|
+
<Setter Property="ClickMode" Value="Press" />
|
72
|
+
<Setter Property="Template">
|
73
|
+
<Setter.Value>
|
74
|
+
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
75
|
+
<Border
|
76
|
+
x:Name="templateRoot"
|
77
|
+
Background="{TemplateBinding Background}"
|
78
|
+
BorderBrush="{StaticResource ComboBox.Static.Border}"
|
79
|
+
BorderThickness="{TemplateBinding BorderThickness}"
|
80
|
+
SnapsToDevicePixels="true">-->
|
81
|
+
<!-- 以下も省略 -->
|
82
|
+
|
83
|
+
<!-- いろいろ省略 -->
|
84
|
+
<!--<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}"/>
|
85
|
+
<ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}"/>
|
86
|
+
<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}"/>-->
|
87
|
+
</Window.Resources>
|
88
|
+
<DockPanel>
|
89
|
+
<ComboBox
|
90
|
+
Background="Red"
|
91
|
+
DockPanel.Dock="Top"
|
92
|
+
Style="{DynamicResource ComboBoxStyle1}" />
|
93
|
+
<Button
|
94
|
+
Click="Button2_Click"
|
95
|
+
Content="更新"
|
96
|
+
DockPanel.Dock="Top" />
|
97
|
+
<DataGrid
|
98
|
+
AutoGenerateColumns="False"
|
99
|
+
ItemsSource="{Binding Records}"
|
100
|
+
SelectionUnit="CellOrRowHeader">
|
101
|
+
<DataGrid.Columns>
|
102
|
+
|
103
|
+
<DataGridComboBoxColumn
|
104
|
+
DisplayMemberPath="Label"
|
105
|
+
Header="ComboBoxColumn"
|
106
|
+
ItemsSource="{StaticResource ModeToComboBoxGrps}"
|
107
|
+
SelectedValueBinding="{Binding Mode}"
|
108
|
+
SelectedValuePath="Value">
|
109
|
+
<DataGridComboBoxColumn.CellStyle>
|
110
|
+
<Style TargetType="DataGridCell">
|
111
|
+
<Style.Triggers>
|
112
|
+
<DataTrigger Binding="{Binding IsModeChange}" Value="True">
|
113
|
+
<Setter Property="Background" Value="LightSalmon" />
|
114
|
+
</DataTrigger>
|
115
|
+
</Style.Triggers>
|
116
|
+
</Style>
|
117
|
+
</DataGridComboBoxColumn.CellStyle>
|
118
|
+
</DataGridComboBoxColumn>
|
119
|
+
|
120
|
+
<DataGridTemplateColumn Header="Test">
|
121
|
+
<DataGridTemplateColumn.CellTemplate>
|
122
|
+
<DataTemplate>
|
123
|
+
<ComboBox
|
124
|
+
DisplayMemberPath="Label"
|
125
|
+
ItemsSource="{StaticResource ModeToComboBoxGrps}"
|
126
|
+
SelectedValue="{Binding Mode, UpdateSourceTrigger=PropertyChanged}"
|
127
|
+
SelectedValuePath="Value">
|
128
|
+
<ComboBox.Style>
|
129
|
+
<Style BasedOn="{StaticResource ComboBoxStyle1}" TargetType="ComboBox">
|
130
|
+
<Style.Triggers>
|
131
|
+
<DataTrigger Binding="{Binding IsModeChange}" Value="True">
|
132
|
+
<Setter Property="Background" Value="LightSalmon" />
|
133
|
+
</DataTrigger>
|
134
|
+
</Style.Triggers>
|
135
|
+
</Style>
|
136
|
+
</ComboBox.Style>
|
137
|
+
</ComboBox>
|
138
|
+
</DataTemplate>
|
139
|
+
</DataGridTemplateColumn.CellTemplate>
|
140
|
+
</DataGridTemplateColumn>
|
141
|
+
</DataGrid.Columns>
|
142
|
+
</DataGrid>
|
143
|
+
</DockPanel>
|
144
|
+
</Window>
|
145
|
+
```
|
146
|
+
|
147
|
+
```cs
|
148
|
+
using System.Collections.Generic;
|
149
|
+
using System.ComponentModel;
|
150
|
+
using System.Runtime.CompilerServices;
|
151
|
+
using System.Windows;
|
152
|
+
|
153
|
+
namespace Questions352305
|
154
|
+
{
|
155
|
+
public class Record : Observable
|
156
|
+
{
|
157
|
+
public int Mode
|
158
|
+
{
|
159
|
+
get => _Mode;
|
160
|
+
set { if (SetProperty(ref _Mode, value)) IsModeChange = true; }
|
161
|
+
}
|
162
|
+
private int _Mode;
|
163
|
+
|
164
|
+
public bool IsModeChange { get => _IsModeChange; set => SetProperty(ref _IsModeChange, value); }
|
165
|
+
private bool _IsModeChange;
|
166
|
+
}
|
167
|
+
|
168
|
+
public class ModeToComboBoxGrp
|
169
|
+
{
|
170
|
+
public string Label { get; set; }
|
171
|
+
public int Value { get; set; }
|
172
|
+
}
|
173
|
+
|
174
|
+
public partial class MainWindow : Window
|
175
|
+
{
|
176
|
+
public List<Record> Records { get; } = new List<Record>();
|
177
|
+
|
178
|
+
public MainWindow()
|
179
|
+
{
|
180
|
+
InitializeComponent();
|
181
|
+
DataContext = this;
|
182
|
+
|
183
|
+
Records.Add(new Record());
|
184
|
+
Records.Add(new Record());
|
185
|
+
Records.Add(new Record());
|
186
|
+
}
|
187
|
+
|
188
|
+
private void Button2_Click(object sender, RoutedEventArgs e)
|
189
|
+
{
|
190
|
+
foreach (var record in Records)
|
191
|
+
{
|
192
|
+
record.IsModeChange = false;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
public class Observable : INotifyPropertyChanged
|
198
|
+
{
|
199
|
+
public event PropertyChangedEventHandler PropertyChanged;
|
200
|
+
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
201
|
+
{
|
202
|
+
if (Equals(storage, value)) return false;
|
203
|
+
storage = value;
|
204
|
+
OnPropertyChanged(propertyName);
|
205
|
+
return true;
|
206
|
+
}
|
207
|
+
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
208
|
+
}
|
209
|
+
}
|
210
|
+
```
|
211
211
|

|
1
検証コード追記
answer
CHANGED
@@ -38,4 +38,174 @@
|
|
38
38
|
<Style TargetType="ComboBox" BasedOn="{StaticResource ComboBoxStyle1}">
|
39
39
|
```
|
40
40
|
のように今出力したスタイルを受け継ぐようにします。
|
41
|
-
これでおそらく`Background`の変更が反映されると思います。
|
41
|
+
これでおそらく`Background`の変更が反映されると思います。
|
42
|
+
|
43
|
+
---
|
44
|
+
|
45
|
+
検証コード追記
|
46
|
+
|
47
|
+
```xaml
|
48
|
+
<Window
|
49
|
+
x:Class="Questions352305.MainWindow"
|
50
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
51
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
52
|
+
xmlns:local="clr-namespace:Questions352305"
|
53
|
+
xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero2"
|
54
|
+
Width="800"
|
55
|
+
Height="450">
|
56
|
+
<Window.Resources>
|
57
|
+
<x:Array x:Key="ModeToComboBoxGrps" Type="{x:Type local:ModeToComboBoxGrp}">
|
58
|
+
<local:ModeToComboBoxGrp Label="0:TOP" Value="0" />
|
59
|
+
<local:ModeToComboBoxGrp Label="1:LOW" Value="1" />
|
60
|
+
</x:Array>
|
61
|
+
|
62
|
+
<!-- いろいろ省略 -->
|
63
|
+
<!--<Style x:Key="FocusVisual" />
|
64
|
+
<SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF" />
|
65
|
+
<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}" />-->
|
66
|
+
|
67
|
+
<!--<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
68
|
+
<Setter Property="OverridesDefaultStyle" Value="true" />
|
69
|
+
<Setter Property="IsTabStop" Value="false" />
|
70
|
+
<Setter Property="Focusable" Value="false" />
|
71
|
+
<Setter Property="ClickMode" Value="Press" />
|
72
|
+
<Setter Property="Template">
|
73
|
+
<Setter.Value>
|
74
|
+
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
75
|
+
<Border
|
76
|
+
x:Name="templateRoot"
|
77
|
+
Background="{TemplateBinding Background}"
|
78
|
+
BorderBrush="{StaticResource ComboBox.Static.Border}"
|
79
|
+
BorderThickness="{TemplateBinding BorderThickness}"
|
80
|
+
SnapsToDevicePixels="true">-->
|
81
|
+
<!-- 以下も省略 -->
|
82
|
+
|
83
|
+
<!-- いろいろ省略 -->
|
84
|
+
<!--<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}"/>
|
85
|
+
<ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}"/>
|
86
|
+
<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}"/>-->
|
87
|
+
</Window.Resources>
|
88
|
+
<DockPanel>
|
89
|
+
<ComboBox
|
90
|
+
Background="Red"
|
91
|
+
DockPanel.Dock="Top"
|
92
|
+
Style="{DynamicResource ComboBoxStyle1}" />
|
93
|
+
<Button
|
94
|
+
Click="Button2_Click"
|
95
|
+
Content="更新"
|
96
|
+
DockPanel.Dock="Top" />
|
97
|
+
<DataGrid
|
98
|
+
AutoGenerateColumns="False"
|
99
|
+
ItemsSource="{Binding Records}"
|
100
|
+
SelectionUnit="CellOrRowHeader">
|
101
|
+
<DataGrid.Columns>
|
102
|
+
|
103
|
+
<DataGridComboBoxColumn
|
104
|
+
DisplayMemberPath="Label"
|
105
|
+
Header="ComboBoxColumn"
|
106
|
+
ItemsSource="{StaticResource ModeToComboBoxGrps}"
|
107
|
+
SelectedValueBinding="{Binding Mode}"
|
108
|
+
SelectedValuePath="Value">
|
109
|
+
<DataGridComboBoxColumn.CellStyle>
|
110
|
+
<Style TargetType="DataGridCell">
|
111
|
+
<Style.Triggers>
|
112
|
+
<DataTrigger Binding="{Binding IsModeChange}" Value="True">
|
113
|
+
<Setter Property="Background" Value="LightSalmon" />
|
114
|
+
</DataTrigger>
|
115
|
+
</Style.Triggers>
|
116
|
+
</Style>
|
117
|
+
</DataGridComboBoxColumn.CellStyle>
|
118
|
+
</DataGridComboBoxColumn>
|
119
|
+
|
120
|
+
<DataGridTemplateColumn Header="Test">
|
121
|
+
<DataGridTemplateColumn.CellTemplate>
|
122
|
+
<DataTemplate>
|
123
|
+
<ComboBox
|
124
|
+
DisplayMemberPath="Label"
|
125
|
+
ItemsSource="{StaticResource ModeToComboBoxGrps}"
|
126
|
+
SelectedValue="{Binding Mode, UpdateSourceTrigger=PropertyChanged}"
|
127
|
+
SelectedValuePath="Value">
|
128
|
+
<ComboBox.Style>
|
129
|
+
<Style BasedOn="{StaticResource ComboBoxStyle1}" TargetType="ComboBox">
|
130
|
+
<Style.Triggers>
|
131
|
+
<DataTrigger Binding="{Binding IsModeChange}" Value="True">
|
132
|
+
<Setter Property="Background" Value="LightSalmon" />
|
133
|
+
</DataTrigger>
|
134
|
+
</Style.Triggers>
|
135
|
+
</Style>
|
136
|
+
</ComboBox.Style>
|
137
|
+
</ComboBox>
|
138
|
+
</DataTemplate>
|
139
|
+
</DataGridTemplateColumn.CellTemplate>
|
140
|
+
</DataGridTemplateColumn>
|
141
|
+
</DataGrid.Columns>
|
142
|
+
</DataGrid>
|
143
|
+
</DockPanel>
|
144
|
+
</Window>
|
145
|
+
```
|
146
|
+
|
147
|
+
```C#
|
148
|
+
using System.Collections.Generic;
|
149
|
+
using System.ComponentModel;
|
150
|
+
using System.Runtime.CompilerServices;
|
151
|
+
using System.Windows;
|
152
|
+
|
153
|
+
namespace Questions352305
|
154
|
+
{
|
155
|
+
public class Record : Observable
|
156
|
+
{
|
157
|
+
public int Mode
|
158
|
+
{
|
159
|
+
get => _Mode;
|
160
|
+
set { if (SetProperty(ref _Mode, value)) IsModeChange = true; }
|
161
|
+
}
|
162
|
+
private int _Mode;
|
163
|
+
|
164
|
+
public bool IsModeChange { get => _IsModeChange; set => SetProperty(ref _IsModeChange, value); }
|
165
|
+
private bool _IsModeChange;
|
166
|
+
}
|
167
|
+
|
168
|
+
public class ModeToComboBoxGrp
|
169
|
+
{
|
170
|
+
public string Label { get; set; }
|
171
|
+
public int Value { get; set; }
|
172
|
+
}
|
173
|
+
|
174
|
+
public partial class MainWindow : Window
|
175
|
+
{
|
176
|
+
public List<Record> Records { get; } = new List<Record>();
|
177
|
+
|
178
|
+
public MainWindow()
|
179
|
+
{
|
180
|
+
InitializeComponent();
|
181
|
+
DataContext = this;
|
182
|
+
|
183
|
+
Records.Add(new Record());
|
184
|
+
Records.Add(new Record());
|
185
|
+
Records.Add(new Record());
|
186
|
+
}
|
187
|
+
|
188
|
+
private void Button2_Click(object sender, RoutedEventArgs e)
|
189
|
+
{
|
190
|
+
foreach (var record in Records)
|
191
|
+
{
|
192
|
+
record.IsModeChange = false;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
public class Observable : INotifyPropertyChanged
|
198
|
+
{
|
199
|
+
public event PropertyChangedEventHandler PropertyChanged;
|
200
|
+
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
201
|
+
{
|
202
|
+
if (Equals(storage, value)) return false;
|
203
|
+
storage = value;
|
204
|
+
OnPropertyChanged(propertyName);
|
205
|
+
return true;
|
206
|
+
}
|
207
|
+
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
208
|
+
}
|
209
|
+
}
|
210
|
+
```
|
211
|
+

|