質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,179 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
できるのであれば、①のように解決したいと思っていますが、実装可能でしょうか?
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
--追記---
|
40
|
+
|
41
|
+
これまでは、以下のようなビヘイビア(?)を使用して、ダブルクリックを検知してVMのコマンドを実行していました。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```C#
|
46
|
+
|
47
|
+
public class MouseDoubleClick
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
#region 依存関係プロパティ
|
52
|
+
|
53
|
+
public static DependencyProperty CommandProperty =
|
54
|
+
|
55
|
+
DependencyProperty.RegisterAttached("Command",
|
56
|
+
|
57
|
+
typeof(ICommand),
|
58
|
+
|
59
|
+
typeof(MouseDoubleClick),
|
60
|
+
|
61
|
+
new UIPropertyMetadata(CommandChanged));
|
62
|
+
|
63
|
+
public static DependencyProperty CommandParameterProperty =
|
64
|
+
|
65
|
+
DependencyProperty.RegisterAttached("CommandParameter",
|
66
|
+
|
67
|
+
typeof(object),
|
68
|
+
|
69
|
+
typeof(MouseDoubleClick),
|
70
|
+
|
71
|
+
new UIPropertyMetadata(null));
|
72
|
+
|
73
|
+
#endregion
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
#region イベントハンドラ
|
78
|
+
|
79
|
+
/// <summary>
|
80
|
+
|
81
|
+
///
|
82
|
+
|
83
|
+
/// </summary>
|
84
|
+
|
85
|
+
/// <param name="sender"></param>
|
86
|
+
|
87
|
+
/// <param name="e"></param>
|
88
|
+
|
89
|
+
private static void OnMouseLeftDoubleClick(object sender, MouseButtonEventArgs e)
|
90
|
+
|
91
|
+
{
|
92
|
+
|
93
|
+
if (e.ChangedButton != MouseButton.Left) return;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
var control = sender as Control;
|
98
|
+
|
99
|
+
var command = (ICommand)control.GetValue(CommandProperty);
|
100
|
+
|
101
|
+
var commandParameter = control.GetValue(CommandParameterProperty);
|
102
|
+
|
103
|
+
command.Execute(commandParameter);
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
#endregion
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
#region メソッド
|
112
|
+
|
113
|
+
/// <summary>
|
114
|
+
|
115
|
+
///
|
116
|
+
|
117
|
+
/// </summary>
|
118
|
+
|
119
|
+
/// <param name="target"></param>
|
120
|
+
|
121
|
+
/// <param name="value"></param>
|
122
|
+
|
123
|
+
public static void SetCommand(DependencyObject target, ICommand value)
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
target.SetValue(CommandProperty, value);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
/// <summary>
|
132
|
+
|
133
|
+
///
|
134
|
+
|
135
|
+
/// </summary>
|
136
|
+
|
137
|
+
/// <param name="target"></param>
|
138
|
+
|
139
|
+
/// <param name="value"></param>
|
140
|
+
|
141
|
+
public static void SetCommandParameter(DependencyObject target, object value)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
target.SetValue(CommandParameterProperty, value);
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
/// <summary>
|
150
|
+
|
151
|
+
///
|
152
|
+
|
153
|
+
/// </summary>
|
154
|
+
|
155
|
+
/// <param name="target"></param>
|
156
|
+
|
157
|
+
/// <returns></returns>
|
158
|
+
|
159
|
+
public static object GetCommandParameter(DependencyObject target)
|
160
|
+
|
161
|
+
{
|
162
|
+
|
163
|
+
return target.GetValue(CommandParameterProperty);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
/// <summary>
|
168
|
+
|
169
|
+
///
|
170
|
+
|
171
|
+
/// </summary>
|
172
|
+
|
173
|
+
/// <param name="target"></param>
|
174
|
+
|
175
|
+
/// <param name="e"></param>
|
176
|
+
|
177
|
+
private static void CommandChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
var control = target as Control;
|
182
|
+
|
183
|
+
if (control != null)
|
184
|
+
|
185
|
+
{
|
186
|
+
|
187
|
+
if ((e.NewValue != null) && (e.OldValue == null))
|
188
|
+
|
189
|
+
{
|
190
|
+
|
191
|
+
control.MouseDoubleClick += OnMouseLeftDoubleClick;
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
else if ((e.NewValue == null) && (e.OldValue != null))
|
196
|
+
|
197
|
+
{
|
198
|
+
|
199
|
+
control.MouseDoubleClick -= OnMouseLeftDoubleClick;
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
#endregion
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
```
|