回答編集履歴

2

見直しキャンペーン中

2023/07/26 16:00

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,231 +1,116 @@
1
1
  > DependencyProperty.Registerを行うにあたり「PropertyChangedCallback」を定義したのですがWindow側で設定する値が定数でなければ呼ばれない状況です。
2
2
 
3
-
4
-
5
3
  `DependencyProperty`も`PropertyChangedCallback`も関係ありません(提示コードで問題ありません)
6
-
7
4
  `DataContext`の問題です(なので定数は通ります)
8
-
9
-
10
5
 
11
6
  [XAML バインド エラー]ウィンドウに、エラーが出ているはずです(なければ[出力]ウィンドウでも同じ)
12
7
 
13
-
8
+ ```
14
-
9
+ 重大度レベル データ コンテキスト バインド パス ターゲット ターゲット型 説明 ファイル 行 プロジェクト
10
+ エラー ActionPanelViewModel No ActionPanel.No、名前 = 'panel' String 型 ActionPanelViewModel のオブジェクトに No プロパティが見つかりません。
15
11
  ```
16
12
 
17
- 重大度レベル データ コンテキスト バインド パス ターゲット ターゲット型 説明 ファイル 行 プロジェクト
13
+ つまりもう`ActionPanelViewModel`が、`DataContext`になっています。
14
+ `ApprovalFlowRegistViewModel`側にバインドするなら、例えばこんな感じで探してこなくてはいけません。
18
15
 
16
+ ```xml
19
- エラー ActionPanelViewModel No ActionPanel.No、名前 = 'panel' String 型 ActionPanelViewModel のオブジェクトに No プロパティが見つかりません。
17
+ <views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
20
-
21
18
  ```
22
19
 
23
-
24
-
25
- つまりもう`ActionPanelViewModel`が、`DataContext`になっています。
26
-
27
- `ApprovalFlowRegistViewModel`側にバインドするなら、例えばこんな感じで探してこなくてはいけません。
28
-
29
-
30
-
31
- ```xaml
32
-
33
- <views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
34
-
35
- ```
36
-
37
-
38
-
39
20
  > ※上述のWindowはMainWindowのメニューにあるボタンを押下して表示するものです。
40
-
41
21
  > なので、「RegionManager」は使用できないと認識しております。
42
22
 
43
-
44
-
45
23
  こちらはどうでしょうか?(私はまともに`Prism`を使っていないのでわかってません)
46
-
47
24
  [PopupWindowActionで呼び出したCustomWindow内でRegionを使う - Qiita](https://qiita.com/kwhrkzk/items/d1348aee5fed4cd31603)
48
-
49
-
50
25
 
51
26
  > また、動的に配置したユーザコントロール上で設定される情報をWindow側で管理できるような実装
52
27
 
53
-
54
-
55
28
  K.KATSU2さんが何を指しているのかちょっとわかりませんが、`ActionPanelViewModel`のことでしょうか?
56
-
57
29
  私なら`ApprovalFlowRegistViewModel `に、`ObservableCollection<ActionPanelViewModel>`を持たせますかね(もちろん`AutoWireViewModel`は切ります)
58
30
 
31
+ ---
32
+
33
+ 気になった点(余計なお世話かもしれませんが^^;
34
+
35
+ * `AutoWireViewModel`と`Resources`で、2つ`ApprovalFlowRegistViewModel`ができている
36
+ 何か記載のない特殊な事情があるんでしょうか?ちょっと見たことのない作りです。
37
+ * `Canvas`を使う意味はあるんでしょうか?(ドラッグ移動とかがあるのかな??)
38
+ これだけ見ると`StackPanel`(`ItemsPanel`を特に指定しない)で十分に見えます。
39
+ * ぐちゃぐちゃマージン(デザイナでドラッグするとなる、`"0,0,300,295"`のようなマージン)や、固定サイズはやめる
40
+ `Grid`や`DockPanel`等を使ってちゃんとレイアウトしたほうがいいです。環境によってはレイアウトが崩れます。
41
+ * `_stack`は必要でしょうか?
42
+ `Items.RemoveAt(Items.Count - 1);`で十分に見えます。
43
+ * 使っていないあるいは使う必要のない変数
44
+ `_items`・`_addCommand`等。
59
45
 
60
46
 
61
47
  ---
62
48
 
63
-
64
-
65
- 気になった点(余計なお世話かもしれませんが^^;
66
-
67
-
68
-
69
- * `AutoWireViewModel`と`Resources`で、2つ`ApprovalFlowRegistViewModel`ができている
70
-
71
- 何か記載のない特殊な事情があるんでしょうか?ちょっと見たことのない作りです。
72
-
73
- * `Canvas`を使う意味はあるんでしょうか?(ドラッグ移動とかがあるのかな??)
74
-
75
- これだけ見ると`StackPanel`(`ItemsPanel`を特に指定しない)で十分に見えます。
76
-
77
- * ぐちゃぐちゃマージン(デザイナでドラッグするとなる、`"0,0,300,295"`のようなマージン)や、固定サイズはやめる
78
-
79
- `Grid`や`DockPanel`等を使ってちゃんとレイアウトしたほうがいいです。環境によってはレイアウトが崩れます。
80
-
81
- * `_stack`は必要でしょうか?
82
-
83
- `Items.RemoveAt(Items.Count - 1);`で十分に見えます。
84
-
85
- * 使っていないあるいは使う必要のない変数
86
-
87
- `_items`・`_addCommand`等。
88
-
89
-
90
-
91
-
92
-
93
- ---
94
-
95
-
96
-
97
49
  追記 説明&改善例
98
50
 
99
-
100
-
101
- ```xaml
51
+ ```xml
102
-
103
52
  <Window
104
-
105
53
  x:Class="Questions333961.Views.ApprovalFlowRegist"
106
-
107
54
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
108
-
109
55
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
110
-
111
56
  xmlns:local="clr-namespace:Questions333961.ViewModels"
112
-
113
57
  xmlns:prism="http://prismlibrary.com/"
114
-
115
58
  xmlns:views="clr-namespace:Questions333961.Views"
116
-
117
59
  Width="500"
118
-
119
60
  Height="360"
120
-
121
61
  prism:ViewModelLocator.AutoWireViewModel="True">
122
-
123
62
 
124
-
125
63
  <!--AutoWireViewModel="True"だと、prismが自動的にViewModelを作りWindowのDataContextにセットします-->
126
-
127
64
  <!--<Window.Resources>
128
-
129
65
  <local:ApprovalFlowRegistViewModel x:Key="ViewModel" />
130
-
131
66
  </Window.Resources>-->
132
-
133
67
  <!--<DockPanel DataContext="{StaticResource ViewModel}">-->
134
-
135
68
  <DockPanel>
136
-
137
69
  <StackPanel DockPanel.Dock="Right">
138
-
139
70
  <Button
140
-
141
71
  MinWidth="90"
142
-
143
72
  Margin="10"
144
-
145
73
  Command="{Binding AddCommand}"
146
-
147
74
  Content="追加" />
148
-
149
75
  <Button
150
-
151
76
  MinWidth="90"
152
-
153
77
  Margin="10"
154
-
155
78
  Command="{Binding DelCommand}"
156
-
157
79
  Content="削除" />
158
-
159
80
  </StackPanel>
160
-
161
81
  <DockPanel>
162
-
163
82
  <Grid DockPanel.Dock="Top">
164
-
165
83
  <Grid.ColumnDefinitions>
166
-
167
84
  <ColumnDefinition Width="Auto" />
168
-
169
85
  <ColumnDefinition />
170
-
171
86
  </Grid.ColumnDefinitions>
172
-
173
87
  <Label Content="承認フロー名:" />
174
-
175
88
  <TextBox Grid.Column="1" />
176
-
177
89
  </Grid>
178
-
179
90
  <ItemsControl ItemsSource="{Binding Items}">
180
-
181
91
 
182
-
183
92
  <!--ItemsPanelが無指定だとStackPanelで縦に並びます-->
184
-
185
93
  <!--<ItemsControl.ItemsPanel>
186
-
187
94
  <ItemsPanelTemplate>
188
-
189
95
  <Canvas />
190
-
191
96
  </ItemsPanelTemplate>
192
-
193
97
  </ItemsControl.ItemsPanel>-->
194
-
195
98
  <ItemsControl.ItemTemplate>
196
-
197
99
  <DataTemplate DataType="local:Item">
198
-
199
100
  <views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
200
-
201
101
  <!--<views:ActionPanel No="{Binding No}" />-->
202
-
203
102
  </DataTemplate>
204
-
205
103
  </ItemsControl.ItemTemplate>
206
-
207
104
 
208
-
209
105
  <!--ここも必要ないですしItemのXYもいりません-->
210
-
211
106
  <!--<ItemsControl.ItemContainerStyle>
212
-
213
107
  <Style TargetType="ContentPresenter">
214
-
215
108
  <Setter Property="Canvas.Top" Value="{Binding Y}" />
216
-
217
109
  <Setter Property="Canvas.Left" Value="{Binding X}" />
218
-
219
110
  </Style>
220
-
221
111
  </ItemsControl.ItemContainerStyle>-->
222
-
223
112
  </ItemsControl>
224
-
225
113
  </DockPanel>
226
-
227
114
  </DockPanel>
228
-
229
115
  </Window>
230
-
231
116
  ```

1

追記 説明&改善例

2021/04/19 14:36

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -85,3 +85,147 @@
85
85
  * 使っていないあるいは使う必要のない変数
86
86
 
87
87
  `_items`・`_addCommand`等。
88
+
89
+
90
+
91
+
92
+
93
+ ---
94
+
95
+
96
+
97
+ 追記 説明&改善例
98
+
99
+
100
+
101
+ ```xaml
102
+
103
+ <Window
104
+
105
+ x:Class="Questions333961.Views.ApprovalFlowRegist"
106
+
107
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
108
+
109
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
110
+
111
+ xmlns:local="clr-namespace:Questions333961.ViewModels"
112
+
113
+ xmlns:prism="http://prismlibrary.com/"
114
+
115
+ xmlns:views="clr-namespace:Questions333961.Views"
116
+
117
+ Width="500"
118
+
119
+ Height="360"
120
+
121
+ prism:ViewModelLocator.AutoWireViewModel="True">
122
+
123
+
124
+
125
+ <!--AutoWireViewModel="True"だと、prismが自動的にViewModelを作りWindowのDataContextにセットします-->
126
+
127
+ <!--<Window.Resources>
128
+
129
+ <local:ApprovalFlowRegistViewModel x:Key="ViewModel" />
130
+
131
+ </Window.Resources>-->
132
+
133
+ <!--<DockPanel DataContext="{StaticResource ViewModel}">-->
134
+
135
+ <DockPanel>
136
+
137
+ <StackPanel DockPanel.Dock="Right">
138
+
139
+ <Button
140
+
141
+ MinWidth="90"
142
+
143
+ Margin="10"
144
+
145
+ Command="{Binding AddCommand}"
146
+
147
+ Content="追加" />
148
+
149
+ <Button
150
+
151
+ MinWidth="90"
152
+
153
+ Margin="10"
154
+
155
+ Command="{Binding DelCommand}"
156
+
157
+ Content="削除" />
158
+
159
+ </StackPanel>
160
+
161
+ <DockPanel>
162
+
163
+ <Grid DockPanel.Dock="Top">
164
+
165
+ <Grid.ColumnDefinitions>
166
+
167
+ <ColumnDefinition Width="Auto" />
168
+
169
+ <ColumnDefinition />
170
+
171
+ </Grid.ColumnDefinitions>
172
+
173
+ <Label Content="承認フロー名:" />
174
+
175
+ <TextBox Grid.Column="1" />
176
+
177
+ </Grid>
178
+
179
+ <ItemsControl ItemsSource="{Binding Items}">
180
+
181
+
182
+
183
+ <!--ItemsPanelが無指定だとStackPanelで縦に並びます-->
184
+
185
+ <!--<ItemsControl.ItemsPanel>
186
+
187
+ <ItemsPanelTemplate>
188
+
189
+ <Canvas />
190
+
191
+ </ItemsPanelTemplate>
192
+
193
+ </ItemsControl.ItemsPanel>-->
194
+
195
+ <ItemsControl.ItemTemplate>
196
+
197
+ <DataTemplate DataType="local:Item">
198
+
199
+ <views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
200
+
201
+ <!--<views:ActionPanel No="{Binding No}" />-->
202
+
203
+ </DataTemplate>
204
+
205
+ </ItemsControl.ItemTemplate>
206
+
207
+
208
+
209
+ <!--ここも必要ないですしItemのXYもいりません-->
210
+
211
+ <!--<ItemsControl.ItemContainerStyle>
212
+
213
+ <Style TargetType="ContentPresenter">
214
+
215
+ <Setter Property="Canvas.Top" Value="{Binding Y}" />
216
+
217
+ <Setter Property="Canvas.Left" Value="{Binding X}" />
218
+
219
+ </Style>
220
+
221
+ </ItemsControl.ItemContainerStyle>-->
222
+
223
+ </ItemsControl>
224
+
225
+ </DockPanel>
226
+
227
+ </DockPanel>
228
+
229
+ </Window>
230
+
231
+ ```