質問編集履歴

4

最終の動作コードへ更新

2019/04/16 05:30

投稿

Base
Base

スコア28

test CHANGED
File without changes
test CHANGED
@@ -64,7 +64,7 @@
64
64
 
65
65
  <ToggleButton.ContextMenu>
66
66
 
67
- <ContextMenu IsOpen="{Binding ShowMeoDataOnly, Mode=TwoWay}" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}}">
67
+ <ContextMenu DataContext="{StaticResource Proxy}" IsOpen="{Binding Data.ShowMeoDataOnly, Mode=TwoWay}">
68
68
 
69
69
  <MenuItem Command="{Binding Source={StaticResource Proxy}, Path=Data.MyCommand}">
70
70
 

3

頂いた情報によるコード更新

2019/04/16 05:30

投稿

Base
Base

スコア28

test CHANGED
File without changes
test CHANGED
@@ -34,9 +34,15 @@
34
34
 
35
35
  ```xmal
36
36
 
37
-
37
+ <Window.Resources>
38
+
38
-
39
+ <local:BindingProxy x:Key="Proxy" Data="{Binding}" />
40
+
41
+ </Window.Resources>
42
+
43
+
44
+
39
- <Grid>
45
+ <Grid>
40
46
 
41
47
  <StackPanel>
42
48
 
@@ -58,9 +64,9 @@
58
64
 
59
65
  <ToggleButton.ContextMenu>
60
66
 
67
+ <ContextMenu IsOpen="{Binding ShowMeoDataOnly, Mode=TwoWay}" PlacementTarget="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}}">
68
+
61
- <ContextMenu IsOpen="{Binding ShowMeoDataOnly, Mode=TwoWay}">
69
+ <MenuItem Command="{Binding Source={StaticResource Proxy}, Path=Data.MyCommand}">
62
-
63
- <MenuItem>
64
70
 
65
71
  <MenuItem.Header>
66
72
 
@@ -70,7 +76,7 @@
70
76
 
71
77
  </MenuItem>
72
78
 
73
- <MenuItem>
79
+ <MenuItem Command="{Binding Source={StaticResource Proxy}, Path=Data.MyCommand}">
74
80
 
75
81
  <MenuItem.Header>
76
82
 
@@ -80,7 +86,7 @@
80
86
 
81
87
  </MenuItem>
82
88
 
83
- <MenuItem>
89
+ <MenuItem Command="{Binding Source={StaticResource Proxy}, Path=Data.MyCommand}">
84
90
 
85
91
  <MenuItem.Header>
86
92
 
@@ -104,6 +110,8 @@
104
110
 
105
111
  </StackPanel>
106
112
 
113
+ <!--<Path Width="10" Height="5" Stretch="Fill" Fill="Black" Data="F1 M0,0 L10,0 L5,10 Z " />-->
114
+
107
115
  <Border Width="8" />
108
116
 
109
117
  </WrapPanel>
@@ -184,6 +192,54 @@
184
192
 
185
193
 
186
194
 
195
+ ```BindingProxy
196
+
197
+
198
+
199
+ using System.Windows;
200
+
201
+
202
+
203
+ // BindingProxy.csを作成
204
+
205
+
206
+
207
+ public class BindingProxy : Freezable
208
+
209
+ {
210
+
211
+ protected override Freezable CreateInstanceCore()
212
+
213
+ {
214
+
215
+ return new BindingProxy();
216
+
217
+ }
218
+
219
+
220
+
221
+ public object Data
222
+
223
+ {
224
+
225
+ get { return (object)GetValue(DataProperty); }
226
+
227
+ set { SetValue(DataProperty, value); }
228
+
229
+ }
230
+
231
+
232
+
233
+ public static readonly DependencyProperty DataProperty =
234
+
235
+ DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null));
236
+
237
+ }
238
+
239
+ ```
240
+
241
+
242
+
187
243
  ### 試したこと
188
244
 
189
245
 

2

ご指摘頂いた点、修正。・どのような手順を取るとどうなるようにしたいのか ・今はどうなるのか

2019/04/16 02:46

投稿

Base
Base

スコア28

test CHANGED
@@ -1 +1 @@
1
- [WPF][MVVM] ToggleButton使用ContextMenu表示
1
+ [WPF][MVVM] ToggleButtonを押した時ContextMenu表示したい
test CHANGED
@@ -6,6 +6,16 @@
6
6
 
7
7
  WPF + Visual Studio2015にてトグルボタンのメニューを作成中です。
8
8
 
9
+
10
+
11
+ トグルボタンを押した時に、展開してメニューが表示するようにしたいです。
12
+
13
+ 今は、押しても何もメニューが展開されない状態です。
14
+
15
+ ViewModelでの、フラグの切り替えは出来ていますが、ContextMenuを展開するのにはどうしたら良いのかを調べています。
16
+
17
+  
18
+
9
19
  色々調べましたが、情報を探し出せなかった為、ご教授頂けますと幸いです。
10
20
 
11
21
 

1

一部修正

2019/04/14 23:56

投稿

Base
Base

スコア28

test CHANGED
File without changes
test CHANGED
@@ -94,8 +94,6 @@
94
94
 
95
95
  </StackPanel>
96
96
 
97
- <Path Width="10" Height="5" Stretch="Fill" Fill="Black" Data="F1 M0,0 L10,0 L5,10 Z " />
98
-
99
97
  <Border Width="8" />
100
98
 
101
99
  </WrapPanel>