回答編集履歴

3

見直しキャンペーン中

2023/07/25 13:52

投稿

TN8001
TN8001

スコア9807

test CHANGED
@@ -1,367 +1,176 @@
1
1
  おそらくダイアログ云々は関係なくて、`MainWindow`に置いても出ないんじゃないでしょうか?
2
-
3
2
  現象から推測すると、
4
3
 
5
-
6
-
7
4
  * `XXX.xaml`で`AutoWireViewModel="True"`された上`XXXViewModel`がある
8
-
9
- つまり`DataContext`が違うのではないかということです。
5
+ つまり`DataContext`が違うのではないかということです。
10
-
11
6
  * `XXX.xaml`の`Param`を表示するコントロールで`RelativeSource`忘れ
12
-
13
- `DependencyProperty`の`Param`を中からバインドするなら、`FindAncestor`がいると思いますができていない?
7
+ `DependencyProperty`の`Param`を中からバインドするなら、`FindAncestor`がいると思いますができていない?
14
-
15
-
16
8
 
17
9
  どちらにせよ「出力」ウィンドウや「XAML バインド エラー」ウィンドウに、エラー表示が出ます。
18
-
19
10
  エラーが出ていなければはずれですので、`XXX.xaml`・`XXX.xaml.cs`も追記してください。
20
-
21
-
22
-
23
11
 
24
12
 
25
13
  > DependencyProperty で実装しており、デバッガ で確認したところ、その setter も呼ばれていない
26
14
 
27
-
28
-
29
15
  CLRプロパティラッパーが呼ばれないのは仕様です。直接`SetValue`が呼ばれます。
30
-
31
-
32
-
33
16
  [XAML Loading and Dependency Properties - WPF .NET Framework | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/desktop/wpf/advanced/xaml-loading-and-dependency-properties)
34
-
35
-
36
17
 
37
18
  ---
38
19
 
39
-
40
-
41
-
42
-
43
20
  検証コード
44
-
45
-
46
-
47
- Dialog.xaml
21
+ ```xml:Dialog.xaml
48
-
49
- ```xaml
50
-
51
22
  <UserControl
52
-
53
23
  x:Class="Questions309079.Views.Dialog"
54
-
55
24
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
56
-
57
25
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
58
-
59
26
  xmlns:local="clr-namespace:Questions309079.Views"
60
-
61
27
  xmlns:prism="http://prismlibrary.com/"
62
-
63
28
  x:Name="dialog"
64
-
65
29
  prism:ViewModelLocator.AutoWireViewModel="True">
66
-
67
30
  <StackPanel>
68
-
69
31
  <GroupBox Margin="5" Header="Dialog VM ⇆ XXX DP">
70
-
71
32
  <local:XXX
72
-
73
33
  x:Name="XXX"
74
-
75
34
  Param1="{Binding DataContext.Param1.Value, ElementName=dialog, Mode=TwoWay}"
76
-
77
35
  Param2="{Binding DataContext.Param2.Value, ElementName=dialog, Mode=TwoWay}" />
78
-
79
36
  </GroupBox>
80
37
 
81
-
82
-
83
38
  <GroupBox Margin="5" Header="XXX DP ⇆ XXX VM">
84
-
85
39
  <local:XXX
86
-
87
40
  Param1="{Binding Param1.Value, Mode=TwoWay}"
88
-
89
41
  Param2="{Binding Param2.Value, Mode=TwoWay}" />
90
-
91
42
  </GroupBox>
92
43
 
93
-
94
-
95
44
  <GroupBox Margin="5" Header="Dialog VM ⇆ XXX DP ⇆ XXX VM">
96
-
97
45
  <TextBlock Text="こういうことをしようとしている??&#xa;だったらXXX DPもXXX VMもいらんでしょ?という話" />
98
-
99
46
  </GroupBox>
100
47
 
101
-
102
-
103
48
  <GroupBox Margin="5" Header="Dialog">
104
-
105
49
  <StackPanel>
106
-
107
50
  <HeaderedContentControl Header="Dialog VM Param1">
108
-
109
51
  <TextBox Text="{Binding Param1.Value, UpdateSourceTrigger=PropertyChanged}" />
110
-
111
52
  </HeaderedContentControl>
112
-
113
53
  <HeaderedContentControl Header="Dialog VM Param2">
114
-
115
54
  <TextBox Text="{Binding Param2.Value, UpdateSourceTrigger=PropertyChanged}" />
116
-
117
55
  </HeaderedContentControl>
118
-
119
56
  </StackPanel>
120
-
121
57
  </GroupBox>
122
-
123
58
  </StackPanel>
124
-
125
59
  </UserControl>
126
-
127
60
  ```
128
61
 
129
-
130
-
131
- DialogViewModel.cs
62
+ ```cs:DialogViewModel.cs
132
-
133
- ```C#
134
-
135
63
  using Prism.Mvvm;
136
-
137
64
  using Prism.Services.Dialogs;
138
-
139
65
  using Reactive.Bindings;
140
-
141
66
  using System;
142
67
 
143
-
144
-
145
68
  namespace Questions309079.ViewModels
146
-
147
69
  {
148
-
149
70
  public class DialogViewModel : BindableBase, IDialogAware
150
-
151
71
  {
152
-
153
72
  public ReactiveProperty<string> Param1 { get; } = new ReactiveProperty<string>("aaa");
154
-
155
73
  public ReactiveProperty<string> Param2 { get; } = new ReactiveProperty<string>("bbb");
156
-
157
-
158
74
 
159
75
  public string Title => "Dialog";
160
76
 
161
-
162
-
163
77
  public event Action<IDialogResult> RequestClose;
164
78
 
165
-
166
-
167
79
  public void OnDialogOpened(IDialogParameters parameters)
168
-
169
80
  {
170
-
171
81
  Param1.Value = "ABC";
172
-
173
82
  Param2.Value = "DEF";
174
-
175
83
  }
176
84
 
177
-
178
-
179
85
  public void RaiseRequestClose(IDialogResult dialogResult) => RequestClose?.Invoke(dialogResult);
180
-
181
86
  public bool CanCloseDialog() => true;
182
-
183
87
  public void OnDialogClosed() { }
184
-
185
88
  }
186
-
187
89
  }
188
-
189
90
  ```
190
-
191
-
192
91
 
193
92
  ---
194
93
 
195
-
196
-
197
- XXX.xaml
94
+ ```xml:XXX.xaml
198
-
199
- ```xaml
200
-
201
95
  <UserControl
202
-
203
96
  x:Class="Questions309079.Views.XXX"
204
-
205
97
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
206
-
207
98
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
208
-
209
99
  xmlns:local="clr-namespace:Questions309079.Views"
210
-
211
100
  xmlns:prism="http://prismlibrary.com/"
212
-
213
101
  prism:ViewModelLocator.AutoWireViewModel="True">
214
-
215
102
  <Grid>
216
-
217
103
  <Grid.ColumnDefinitions>
218
-
219
104
  <ColumnDefinition />
220
-
221
105
  <ColumnDefinition />
222
-
223
106
  </Grid.ColumnDefinitions>
224
-
225
107
  <StackPanel>
226
-
227
108
  <HeaderedContentControl Header="XXX DP Param1">
228
-
229
109
  <TextBox Text="{Binding Param1, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:XXX}}, UpdateSourceTrigger=PropertyChanged}" />
230
-
231
110
  </HeaderedContentControl>
232
-
233
111
  <HeaderedContentControl Header="XXX DP Param2">
234
-
235
112
  <TextBox Text="{Binding Param2, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:XXX}}, UpdateSourceTrigger=PropertyChanged}" />
236
-
237
113
  </HeaderedContentControl>
238
-
239
114
  </StackPanel>
240
-
241
115
 
242
-
243
116
  <StackPanel Grid.Column="1">
244
-
245
117
  <HeaderedContentControl Header="XXX VM Param1">
246
-
247
118
  <TextBox Text="{Binding Param1.Value, UpdateSourceTrigger=PropertyChanged}" />
248
-
249
119
  </HeaderedContentControl>
250
-
251
120
  <HeaderedContentControl Header="XXX VM Param2">
252
-
253
121
  <TextBox Text="{Binding Param2.Value, UpdateSourceTrigger=PropertyChanged}" />
254
-
255
122
  </HeaderedContentControl>
256
-
257
123
  </StackPanel>
258
-
259
124
  </Grid>
260
-
261
125
  </UserControl>
262
-
263
126
  ```
264
127
 
265
-
266
-
267
- XXX.xaml.cs
128
+ ```cs:XXX.xaml.cs
268
-
269
- ```C#
270
-
271
129
  using System.Diagnostics;
272
-
273
130
  using System.Windows;
274
-
275
131
  using System.Windows.Controls;
276
132
 
277
-
278
-
279
133
  namespace Questions309079.Views
280
-
281
134
  {
282
-
283
135
  public partial class XXX : UserControl
284
-
285
136
  {
286
-
287
137
  public string Param1
288
-
289
138
  {
290
-
291
139
  get => (string)GetValue(Param1Property);
292
-
293
140
  set
294
-
295
141
  {
296
-
297
142
  Debug.WriteLine($"setter:{Param1}->{value}");
298
-
299
143
  SetValue(Param1Property, value);
300
-
301
144
  }
302
-
303
145
  }
304
-
305
146
  public static readonly DependencyProperty Param1Property
306
-
307
147
  = DependencyProperty.Register(nameof(Param1), typeof(string), typeof(XXX),
308
-
309
148
  new PropertyMetadata(string.Empty, OnParam1Changed));
310
-
311
149
  private static void OnParam1Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
312
-
313
150
  => Debug.WriteLine($"OnParam1Changed:{e.OldValue}->{e.NewValue}");
314
151
 
315
152
 
316
-
317
-
318
-
319
153
  public string Param2 { get => (string)GetValue(Param2Property); set => SetValue(Param2Property, value); }
320
-
321
154
  public static readonly DependencyProperty Param2Property
322
-
323
155
  = DependencyProperty.Register(nameof(Param2), typeof(string), typeof(XXX),
324
-
325
156
  new PropertyMetadata(string.Empty));
326
157
 
327
-
328
-
329
158
  public XXX() => InitializeComponent();
330
-
331
159
  }
332
-
333
160
  }
334
-
335
161
  ```
336
162
 
337
-
338
-
339
- XXXViewModel.cs
163
+ ```cs:XXXViewModel.cs
340
-
341
- ```C#
342
-
343
164
  using Reactive.Bindings;
344
165
 
345
-
346
-
347
166
  namespace Questions309079.ViewModels
348
-
349
167
  {
350
-
351
168
  public class XXXViewModel
352
-
353
169
  {
354
-
355
170
  public ReactiveProperty<string> Param1 { get; } = new ReactiveProperty<string>("aaa");
356
-
357
171
  public ReactiveProperty<string> Param2 { get; } = new ReactiveProperty<string>("bbb");
358
-
359
172
  }
360
-
361
173
  }
362
-
363
174
  ```
364
175
 
365
-
366
-
367
176
  ![アプリ画像](cc96a7a1d584cf8c258b9ec28dbc10f0.png)

2

(さらにわかりやすく)更新しました。

2020/12/14 04:25

投稿

TN8001
TN8001

スコア9807

test CHANGED
@@ -38,13 +38,13 @@
38
38
 
39
39
 
40
40
 
41
+
42
+
43
+ 検証コード
44
+
45
+
46
+
41
- ### XXXViewModel は必要
47
+ Dialog.xaml
42
-
43
-
44
-
45
- `XXX`作成時に`XXXViewModel`が`DataContext`に差し込まれますから、`Param.Value`は他から取ってくることになります。
46
-
47
-
48
48
 
49
49
  ```xaml
50
50
 
@@ -66,9 +66,59 @@
66
66
 
67
67
  <StackPanel>
68
68
 
69
+ <GroupBox Margin="5" Header="Dialog VM ⇆ XXX DP">
70
+
71
+ <local:XXX
72
+
73
+ x:Name="XXX"
74
+
75
+ Param1="{Binding DataContext.Param1.Value, ElementName=dialog, Mode=TwoWay}"
76
+
69
- <local:XXX x:Name="XXX" Param="{Binding DataContext.Param.Value, ElementName=dialog, Mode=TwoWay}" />
77
+ Param2="{Binding DataContext.Param2.Value, ElementName=dialog, Mode=TwoWay}" />
78
+
70
-
79
+ </GroupBox>
80
+
81
+
82
+
83
+ <GroupBox Margin="5" Header="XXX DP ⇆ XXX VM">
84
+
85
+ <local:XXX
86
+
87
+ Param1="{Binding Param1.Value, Mode=TwoWay}"
88
+
89
+ Param2="{Binding Param2.Value, Mode=TwoWay}" />
90
+
91
+ </GroupBox>
92
+
93
+
94
+
95
+ <GroupBox Margin="5" Header="Dialog VM ⇆ XXX DP ⇆ XXX VM">
96
+
97
+ <TextBlock Text="こういうことをしようとしている??&#xa;だったらXXX DPもXXX VMもいらんでしょ?という話" />
98
+
99
+ </GroupBox>
100
+
101
+
102
+
103
+ <GroupBox Margin="5" Header="Dialog">
104
+
105
+ <StackPanel>
106
+
107
+ <HeaderedContentControl Header="Dialog VM Param1">
108
+
71
- <TextBox Text="{Binding Param.Value, UpdateSourceTrigger=PropertyChanged}" />
109
+ <TextBox Text="{Binding Param1.Value, UpdateSourceTrigger=PropertyChanged}" />
110
+
111
+ </HeaderedContentControl>
112
+
113
+ <HeaderedContentControl Header="Dialog VM Param2">
114
+
115
+ <TextBox Text="{Binding Param2.Value, UpdateSourceTrigger=PropertyChanged}" />
116
+
117
+ </HeaderedContentControl>
118
+
119
+ </StackPanel>
120
+
121
+ </GroupBox>
72
122
 
73
123
  </StackPanel>
74
124
 
@@ -78,6 +128,74 @@
78
128
 
79
129
 
80
130
 
131
+ DialogViewModel.cs
132
+
133
+ ```C#
134
+
135
+ using Prism.Mvvm;
136
+
137
+ using Prism.Services.Dialogs;
138
+
139
+ using Reactive.Bindings;
140
+
141
+ using System;
142
+
143
+
144
+
145
+ namespace Questions309079.ViewModels
146
+
147
+ {
148
+
149
+ public class DialogViewModel : BindableBase, IDialogAware
150
+
151
+ {
152
+
153
+ public ReactiveProperty<string> Param1 { get; } = new ReactiveProperty<string>("aaa");
154
+
155
+ public ReactiveProperty<string> Param2 { get; } = new ReactiveProperty<string>("bbb");
156
+
157
+
158
+
159
+ public string Title => "Dialog";
160
+
161
+
162
+
163
+ public event Action<IDialogResult> RequestClose;
164
+
165
+
166
+
167
+ public void OnDialogOpened(IDialogParameters parameters)
168
+
169
+ {
170
+
171
+ Param1.Value = "ABC";
172
+
173
+ Param2.Value = "DEF";
174
+
175
+ }
176
+
177
+
178
+
179
+ public void RaiseRequestClose(IDialogResult dialogResult) => RequestClose?.Invoke(dialogResult);
180
+
181
+ public bool CanCloseDialog() => true;
182
+
183
+ public void OnDialogClosed() { }
184
+
185
+ }
186
+
187
+ }
188
+
189
+ ```
190
+
191
+
192
+
193
+ ---
194
+
195
+
196
+
197
+ XXX.xaml
198
+
81
199
  ```xaml
82
200
 
83
201
  <UserControl
@@ -94,15 +212,51 @@
94
212
 
95
213
  prism:ViewModelLocator.AutoWireViewModel="True">
96
214
 
215
+ <Grid>
216
+
217
+ <Grid.ColumnDefinitions>
218
+
219
+ <ColumnDefinition />
220
+
221
+ <ColumnDefinition />
222
+
223
+ </Grid.ColumnDefinitions>
224
+
97
- <StackPanel>
225
+ <StackPanel>
98
-
226
+
99
- <HeaderedContentControl Header="Param">
227
+ <HeaderedContentControl Header="XXX DP Param1">
100
-
228
+
101
- <TextBox Text="{Binding Param, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:XXX}}, UpdateSourceTrigger=PropertyChanged}" />
229
+ <TextBox Text="{Binding Param1, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:XXX}}, UpdateSourceTrigger=PropertyChanged}" />
102
-
230
+
103
- </HeaderedContentControl>
231
+ </HeaderedContentControl>
232
+
104
-
233
+ <HeaderedContentControl Header="XXX DP Param2">
234
+
235
+ <TextBox Text="{Binding Param2, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:XXX}}, UpdateSourceTrigger=PropertyChanged}" />
236
+
237
+ </HeaderedContentControl>
238
+
105
- </StackPanel>
239
+ </StackPanel>
240
+
241
+
242
+
243
+ <StackPanel Grid.Column="1">
244
+
245
+ <HeaderedContentControl Header="XXX VM Param1">
246
+
247
+ <TextBox Text="{Binding Param1.Value, UpdateSourceTrigger=PropertyChanged}" />
248
+
249
+ </HeaderedContentControl>
250
+
251
+ <HeaderedContentControl Header="XXX VM Param2">
252
+
253
+ <TextBox Text="{Binding Param2.Value, UpdateSourceTrigger=PropertyChanged}" />
254
+
255
+ </HeaderedContentControl>
256
+
257
+ </StackPanel>
258
+
259
+ </Grid>
106
260
 
107
261
  </UserControl>
108
262
 
@@ -110,66 +264,104 @@
110
264
 
111
265
 
112
266
 
113
- ### XXXViewModel はなくてもいい
114
-
115
- `XXXViewModel`はカラか、`DialogViewModel`に移しても問題ない場合。
116
-
117
-
118
-
119
- `XXX`で`AutoWireViewModel="False"`すればいいですが、そもそも`DependencyProperty`がいらなくなってしまいますね^^;
120
-
121
-
122
-
123
- ```xaml
124
-
125
- <UserControl
126
-
127
- x:Class="Questions309079.Views.Dialog"
128
-
129
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
130
-
131
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
132
-
133
- xmlns:local="clr-namespace:Questions309079.Views"
134
-
135
- xmlns:prism="http://prismlibrary.com/"
136
-
137
- prism:ViewModelLocator.AutoWireViewModel="True">
138
-
139
- <StackPanel>
140
-
141
- <local:XXX x:Name="XXX" />
142
-
143
- <TextBox Text="{Binding Param.Value, UpdateSourceTrigger=PropertyChanged}" />
144
-
145
- </StackPanel>
146
-
147
- </UserControl>
148
-
149
- ```
150
-
151
-
152
-
153
- ```xaml
154
-
155
- <UserControl
156
-
157
- x:Class="Questions309079.Views.XXX"
158
-
159
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
160
-
161
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
162
-
163
- <StackPanel>
164
-
165
- <HeaderedContentControl Header="Param">
166
-
167
- <TextBox Text="{Binding Param.Value, UpdateSourceTrigger=PropertyChanged}" />
168
-
169
- </HeaderedContentControl>
170
-
171
- </StackPanel>
172
-
173
- </UserControl>
174
-
175
- ```
267
+ XXX.xaml.cs
268
+
269
+ ```C#
270
+
271
+ using System.Diagnostics;
272
+
273
+ using System.Windows;
274
+
275
+ using System.Windows.Controls;
276
+
277
+
278
+
279
+ namespace Questions309079.Views
280
+
281
+ {
282
+
283
+ public partial class XXX : UserControl
284
+
285
+ {
286
+
287
+ public string Param1
288
+
289
+ {
290
+
291
+ get => (string)GetValue(Param1Property);
292
+
293
+ set
294
+
295
+ {
296
+
297
+ Debug.WriteLine($"setter:{Param1}->{value}");
298
+
299
+ SetValue(Param1Property, value);
300
+
301
+ }
302
+
303
+ }
304
+
305
+ public static readonly DependencyProperty Param1Property
306
+
307
+ = DependencyProperty.Register(nameof(Param1), typeof(string), typeof(XXX),
308
+
309
+ new PropertyMetadata(string.Empty, OnParam1Changed));
310
+
311
+ private static void OnParam1Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
312
+
313
+ => Debug.WriteLine($"OnParam1Changed:{e.OldValue}->{e.NewValue}");
314
+
315
+
316
+
317
+
318
+
319
+ public string Param2 { get => (string)GetValue(Param2Property); set => SetValue(Param2Property, value); }
320
+
321
+ public static readonly DependencyProperty Param2Property
322
+
323
+ = DependencyProperty.Register(nameof(Param2), typeof(string), typeof(XXX),
324
+
325
+ new PropertyMetadata(string.Empty));
326
+
327
+
328
+
329
+ public XXX() => InitializeComponent();
330
+
331
+ }
332
+
333
+ }
334
+
335
+ ```
336
+
337
+
338
+
339
+ XXXViewModel.cs
340
+
341
+ ```C#
342
+
343
+ using Reactive.Bindings;
344
+
345
+
346
+
347
+ namespace Questions309079.ViewModels
348
+
349
+ {
350
+
351
+ public class XXXViewModel
352
+
353
+ {
354
+
355
+ public ReactiveProperty<string> Param1 { get; } = new ReactiveProperty<string>("aaa");
356
+
357
+ public ReactiveProperty<string> Param2 { get; } = new ReactiveProperty<string>("bbb");
358
+
359
+ }
360
+
361
+ }
362
+
363
+ ```
364
+
365
+
366
+
367
+ ![アプリ画像](cc96a7a1d584cf8c258b9ec28dbc10f0.png)

1

xaml追加

2020/12/14 04:25

投稿

TN8001
TN8001

スコア9807

test CHANGED
@@ -31,3 +31,145 @@
31
31
 
32
32
 
33
33
  [XAML Loading and Dependency Properties - WPF .NET Framework | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/desktop/wpf/advanced/xaml-loading-and-dependency-properties)
34
+
35
+
36
+
37
+ ---
38
+
39
+
40
+
41
+ ### XXXViewModel は必要
42
+
43
+
44
+
45
+ `XXX`作成時に`XXXViewModel`が`DataContext`に差し込まれますから、`Param.Value`は他から取ってくることになります。
46
+
47
+
48
+
49
+ ```xaml
50
+
51
+ <UserControl
52
+
53
+ x:Class="Questions309079.Views.Dialog"
54
+
55
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
56
+
57
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
58
+
59
+ xmlns:local="clr-namespace:Questions309079.Views"
60
+
61
+ xmlns:prism="http://prismlibrary.com/"
62
+
63
+ x:Name="dialog"
64
+
65
+ prism:ViewModelLocator.AutoWireViewModel="True">
66
+
67
+ <StackPanel>
68
+
69
+ <local:XXX x:Name="XXX" Param="{Binding DataContext.Param.Value, ElementName=dialog, Mode=TwoWay}" />
70
+
71
+ <TextBox Text="{Binding Param.Value, UpdateSourceTrigger=PropertyChanged}" />
72
+
73
+ </StackPanel>
74
+
75
+ </UserControl>
76
+
77
+ ```
78
+
79
+
80
+
81
+ ```xaml
82
+
83
+ <UserControl
84
+
85
+ x:Class="Questions309079.Views.XXX"
86
+
87
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
88
+
89
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
90
+
91
+ xmlns:local="clr-namespace:Questions309079.Views"
92
+
93
+ xmlns:prism="http://prismlibrary.com/"
94
+
95
+ prism:ViewModelLocator.AutoWireViewModel="True">
96
+
97
+ <StackPanel>
98
+
99
+ <HeaderedContentControl Header="Param">
100
+
101
+ <TextBox Text="{Binding Param, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:XXX}}, UpdateSourceTrigger=PropertyChanged}" />
102
+
103
+ </HeaderedContentControl>
104
+
105
+ </StackPanel>
106
+
107
+ </UserControl>
108
+
109
+ ```
110
+
111
+
112
+
113
+ ### XXXViewModel はなくてもいい
114
+
115
+ `XXXViewModel`はカラか、`DialogViewModel`に移しても問題ない場合。
116
+
117
+
118
+
119
+ `XXX`で`AutoWireViewModel="False"`すればいいですが、そもそも`DependencyProperty`がいらなくなってしまいますね^^;
120
+
121
+
122
+
123
+ ```xaml
124
+
125
+ <UserControl
126
+
127
+ x:Class="Questions309079.Views.Dialog"
128
+
129
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
130
+
131
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
132
+
133
+ xmlns:local="clr-namespace:Questions309079.Views"
134
+
135
+ xmlns:prism="http://prismlibrary.com/"
136
+
137
+ prism:ViewModelLocator.AutoWireViewModel="True">
138
+
139
+ <StackPanel>
140
+
141
+ <local:XXX x:Name="XXX" />
142
+
143
+ <TextBox Text="{Binding Param.Value, UpdateSourceTrigger=PropertyChanged}" />
144
+
145
+ </StackPanel>
146
+
147
+ </UserControl>
148
+
149
+ ```
150
+
151
+
152
+
153
+ ```xaml
154
+
155
+ <UserControl
156
+
157
+ x:Class="Questions309079.Views.XXX"
158
+
159
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
160
+
161
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
162
+
163
+ <StackPanel>
164
+
165
+ <HeaderedContentControl Header="Param">
166
+
167
+ <TextBox Text="{Binding Param.Value, UpdateSourceTrigger=PropertyChanged}" />
168
+
169
+ </HeaderedContentControl>
170
+
171
+ </StackPanel>
172
+
173
+ </UserControl>
174
+
175
+ ```