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

質問編集履歴

1

コードの追加

2019/08/11 08:38

投稿

OXamarin
OXamarin

スコア59

title CHANGED
File without changes
body CHANGED
@@ -15,4 +15,92 @@
15
15
 
16
16
  ② 明細以外の箇所をクリックすると、SelectedIndex = -1 とする
17
17
 
18
- できるのであれば、①のように解決したいと思っていますが、実装可能でしょうか?
18
+ できるのであれば、①のように解決したいと思っていますが、実装可能でしょうか?
19
+
20
+ --追記---
21
+ これまでは、以下のようなビヘイビア(?)を使用して、ダブルクリックを検知してVMのコマンドを実行していました。
22
+
23
+ ```C#
24
+ public class MouseDoubleClick
25
+ {
26
+ #region 依存関係プロパティ
27
+ public static DependencyProperty CommandProperty =
28
+ DependencyProperty.RegisterAttached("Command",
29
+ typeof(ICommand),
30
+ typeof(MouseDoubleClick),
31
+ new UIPropertyMetadata(CommandChanged));
32
+ public static DependencyProperty CommandParameterProperty =
33
+ DependencyProperty.RegisterAttached("CommandParameter",
34
+ typeof(object),
35
+ typeof(MouseDoubleClick),
36
+ new UIPropertyMetadata(null));
37
+ #endregion
38
+
39
+ #region イベントハンドラ
40
+ /// <summary>
41
+ ///
42
+ /// </summary>
43
+ /// <param name="sender"></param>
44
+ /// <param name="e"></param>
45
+ private static void OnMouseLeftDoubleClick(object sender, MouseButtonEventArgs e)
46
+ {
47
+ if (e.ChangedButton != MouseButton.Left) return;
48
+
49
+ var control = sender as Control;
50
+ var command = (ICommand)control.GetValue(CommandProperty);
51
+ var commandParameter = control.GetValue(CommandParameterProperty);
52
+ command.Execute(commandParameter);
53
+ }
54
+ #endregion
55
+
56
+ #region メソッド
57
+ /// <summary>
58
+ ///
59
+ /// </summary>
60
+ /// <param name="target"></param>
61
+ /// <param name="value"></param>
62
+ public static void SetCommand(DependencyObject target, ICommand value)
63
+ {
64
+ target.SetValue(CommandProperty, value);
65
+ }
66
+ /// <summary>
67
+ ///
68
+ /// </summary>
69
+ /// <param name="target"></param>
70
+ /// <param name="value"></param>
71
+ public static void SetCommandParameter(DependencyObject target, object value)
72
+ {
73
+ target.SetValue(CommandParameterProperty, value);
74
+ }
75
+ /// <summary>
76
+ ///
77
+ /// </summary>
78
+ /// <param name="target"></param>
79
+ /// <returns></returns>
80
+ public static object GetCommandParameter(DependencyObject target)
81
+ {
82
+ return target.GetValue(CommandParameterProperty);
83
+ }
84
+ /// <summary>
85
+ ///
86
+ /// </summary>
87
+ /// <param name="target"></param>
88
+ /// <param name="e"></param>
89
+ private static void CommandChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
90
+ {
91
+ var control = target as Control;
92
+ if (control != null)
93
+ {
94
+ if ((e.NewValue != null) && (e.OldValue == null))
95
+ {
96
+ control.MouseDoubleClick += OnMouseLeftDoubleClick;
97
+ }
98
+ else if ((e.NewValue == null) && (e.OldValue != null))
99
+ {
100
+ control.MouseDoubleClick -= OnMouseLeftDoubleClick;
101
+ }
102
+ }
103
+ }
104
+ #endregion
105
+ }
106
+ ```