回答編集履歴
2
見直しキャンペーン中
answer
CHANGED
@@ -1,116 +1,116 @@
|
|
1
|
-
> DependencyProperty.Registerを行うにあたり「PropertyChangedCallback」を定義したのですがWindow側で設定する値が定数でなければ呼ばれない状況です。
|
2
|
-
|
3
|
-
`DependencyProperty`も`PropertyChangedCallback`も関係ありません(提示コードで問題ありません)
|
4
|
-
`DataContext`の問題です(なので定数は通ります)
|
5
|
-
|
6
|
-
[XAML バインド エラー]ウィンドウに、エラーが出ているはずです(なければ[出力]ウィンドウでも同じ)
|
7
|
-
|
8
|
-
```
|
9
|
-
重大度レベル データ コンテキスト バインド パス ターゲット ターゲット型 説明 ファイル 行 プロジェクト
|
10
|
-
エラー ActionPanelViewModel No ActionPanel.No、名前 = 'panel' String 型 ActionPanelViewModel のオブジェクトに No プロパティが見つかりません。
|
11
|
-
```
|
12
|
-
|
13
|
-
つまりもう`ActionPanelViewModel`が、`DataContext`になっています。
|
14
|
-
`ApprovalFlowRegistViewModel`側にバインドするなら、例えばこんな感じで探してこなくてはいけません。
|
15
|
-
|
16
|
-
```
|
17
|
-
<views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
|
18
|
-
```
|
19
|
-
|
20
|
-
> ※上述のWindowはMainWindowのメニューにあるボタンを押下して表示するものです。
|
21
|
-
> なので、「RegionManager」は使用できないと認識しております。
|
22
|
-
|
23
|
-
こちらはどうでしょうか?(私はまともに`Prism`を使っていないのでわかってません)
|
24
|
-
[PopupWindowActionで呼び出したCustomWindow内でRegionを使う - Qiita](https://qiita.com/kwhrkzk/items/d1348aee5fed4cd31603)
|
25
|
-
|
26
|
-
> また、動的に配置したユーザコントロール上で設定される情報をWindow側で管理できるような実装
|
27
|
-
|
28
|
-
K.KATSU2さんが何を指しているのかちょっとわかりませんが、`ActionPanelViewModel`のことでしょうか?
|
29
|
-
私なら`ApprovalFlowRegistViewModel `に、`ObservableCollection<ActionPanelViewModel>`を持たせますかね(もちろん`AutoWireViewModel`は切ります)
|
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`等。
|
45
|
-
|
46
|
-
|
47
|
-
---
|
48
|
-
|
49
|
-
追記 説明&改善例
|
50
|
-
|
51
|
-
```
|
52
|
-
<Window
|
53
|
-
x:Class="Questions333961.Views.ApprovalFlowRegist"
|
54
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
55
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
56
|
-
xmlns:local="clr-namespace:Questions333961.ViewModels"
|
57
|
-
xmlns:prism="http://prismlibrary.com/"
|
58
|
-
xmlns:views="clr-namespace:Questions333961.Views"
|
59
|
-
Width="500"
|
60
|
-
Height="360"
|
61
|
-
prism:ViewModelLocator.AutoWireViewModel="True">
|
62
|
-
|
63
|
-
<!--AutoWireViewModel="True"だと、prismが自動的にViewModelを作りWindowのDataContextにセットします-->
|
64
|
-
<!--<Window.Resources>
|
65
|
-
<local:ApprovalFlowRegistViewModel x:Key="ViewModel" />
|
66
|
-
</Window.Resources>-->
|
67
|
-
<!--<DockPanel DataContext="{StaticResource ViewModel}">-->
|
68
|
-
<DockPanel>
|
69
|
-
<StackPanel DockPanel.Dock="Right">
|
70
|
-
<Button
|
71
|
-
MinWidth="90"
|
72
|
-
Margin="10"
|
73
|
-
Command="{Binding AddCommand}"
|
74
|
-
Content="追加" />
|
75
|
-
<Button
|
76
|
-
MinWidth="90"
|
77
|
-
Margin="10"
|
78
|
-
Command="{Binding DelCommand}"
|
79
|
-
Content="削除" />
|
80
|
-
</StackPanel>
|
81
|
-
<DockPanel>
|
82
|
-
<Grid DockPanel.Dock="Top">
|
83
|
-
<Grid.ColumnDefinitions>
|
84
|
-
<ColumnDefinition Width="Auto" />
|
85
|
-
<ColumnDefinition />
|
86
|
-
</Grid.ColumnDefinitions>
|
87
|
-
<Label Content="承認フロー名:" />
|
88
|
-
<TextBox Grid.Column="1" />
|
89
|
-
</Grid>
|
90
|
-
<ItemsControl ItemsSource="{Binding Items}">
|
91
|
-
|
92
|
-
<!--ItemsPanelが無指定だとStackPanelで縦に並びます-->
|
93
|
-
<!--<ItemsControl.ItemsPanel>
|
94
|
-
<ItemsPanelTemplate>
|
95
|
-
<Canvas />
|
96
|
-
</ItemsPanelTemplate>
|
97
|
-
</ItemsControl.ItemsPanel>-->
|
98
|
-
<ItemsControl.ItemTemplate>
|
99
|
-
<DataTemplate DataType="local:Item">
|
100
|
-
<views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
|
101
|
-
<!--<views:ActionPanel No="{Binding No}" />-->
|
102
|
-
</DataTemplate>
|
103
|
-
</ItemsControl.ItemTemplate>
|
104
|
-
|
105
|
-
<!--ここも必要ないですしItemのXYもいりません-->
|
106
|
-
<!--<ItemsControl.ItemContainerStyle>
|
107
|
-
<Style TargetType="ContentPresenter">
|
108
|
-
<Setter Property="Canvas.Top" Value="{Binding Y}" />
|
109
|
-
<Setter Property="Canvas.Left" Value="{Binding X}" />
|
110
|
-
</Style>
|
111
|
-
</ItemsControl.ItemContainerStyle>-->
|
112
|
-
</ItemsControl>
|
113
|
-
</DockPanel>
|
114
|
-
</DockPanel>
|
115
|
-
</Window>
|
1
|
+
> DependencyProperty.Registerを行うにあたり「PropertyChangedCallback」を定義したのですがWindow側で設定する値が定数でなければ呼ばれない状況です。
|
2
|
+
|
3
|
+
`DependencyProperty`も`PropertyChangedCallback`も関係ありません(提示コードで問題ありません)
|
4
|
+
`DataContext`の問題です(なので定数は通ります)
|
5
|
+
|
6
|
+
[XAML バインド エラー]ウィンドウに、エラーが出ているはずです(なければ[出力]ウィンドウでも同じ)
|
7
|
+
|
8
|
+
```
|
9
|
+
重大度レベル データ コンテキスト バインド パス ターゲット ターゲット型 説明 ファイル 行 プロジェクト
|
10
|
+
エラー ActionPanelViewModel No ActionPanel.No、名前 = 'panel' String 型 ActionPanelViewModel のオブジェクトに No プロパティが見つかりません。
|
11
|
+
```
|
12
|
+
|
13
|
+
つまりもう`ActionPanelViewModel`が、`DataContext`になっています。
|
14
|
+
`ApprovalFlowRegistViewModel`側にバインドするなら、例えばこんな感じで探してこなくてはいけません。
|
15
|
+
|
16
|
+
```xml
|
17
|
+
<views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
|
18
|
+
```
|
19
|
+
|
20
|
+
> ※上述のWindowはMainWindowのメニューにあるボタンを押下して表示するものです。
|
21
|
+
> なので、「RegionManager」は使用できないと認識しております。
|
22
|
+
|
23
|
+
こちらはどうでしょうか?(私はまともに`Prism`を使っていないのでわかってません)
|
24
|
+
[PopupWindowActionで呼び出したCustomWindow内でRegionを使う - Qiita](https://qiita.com/kwhrkzk/items/d1348aee5fed4cd31603)
|
25
|
+
|
26
|
+
> また、動的に配置したユーザコントロール上で設定される情報をWindow側で管理できるような実装
|
27
|
+
|
28
|
+
K.KATSU2さんが何を指しているのかちょっとわかりませんが、`ActionPanelViewModel`のことでしょうか?
|
29
|
+
私なら`ApprovalFlowRegistViewModel `に、`ObservableCollection<ActionPanelViewModel>`を持たせますかね(もちろん`AutoWireViewModel`は切ります)
|
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`等。
|
45
|
+
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
追記 説明&改善例
|
50
|
+
|
51
|
+
```xml
|
52
|
+
<Window
|
53
|
+
x:Class="Questions333961.Views.ApprovalFlowRegist"
|
54
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
55
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
56
|
+
xmlns:local="clr-namespace:Questions333961.ViewModels"
|
57
|
+
xmlns:prism="http://prismlibrary.com/"
|
58
|
+
xmlns:views="clr-namespace:Questions333961.Views"
|
59
|
+
Width="500"
|
60
|
+
Height="360"
|
61
|
+
prism:ViewModelLocator.AutoWireViewModel="True">
|
62
|
+
|
63
|
+
<!--AutoWireViewModel="True"だと、prismが自動的にViewModelを作りWindowのDataContextにセットします-->
|
64
|
+
<!--<Window.Resources>
|
65
|
+
<local:ApprovalFlowRegistViewModel x:Key="ViewModel" />
|
66
|
+
</Window.Resources>-->
|
67
|
+
<!--<DockPanel DataContext="{StaticResource ViewModel}">-->
|
68
|
+
<DockPanel>
|
69
|
+
<StackPanel DockPanel.Dock="Right">
|
70
|
+
<Button
|
71
|
+
MinWidth="90"
|
72
|
+
Margin="10"
|
73
|
+
Command="{Binding AddCommand}"
|
74
|
+
Content="追加" />
|
75
|
+
<Button
|
76
|
+
MinWidth="90"
|
77
|
+
Margin="10"
|
78
|
+
Command="{Binding DelCommand}"
|
79
|
+
Content="削除" />
|
80
|
+
</StackPanel>
|
81
|
+
<DockPanel>
|
82
|
+
<Grid DockPanel.Dock="Top">
|
83
|
+
<Grid.ColumnDefinitions>
|
84
|
+
<ColumnDefinition Width="Auto" />
|
85
|
+
<ColumnDefinition />
|
86
|
+
</Grid.ColumnDefinitions>
|
87
|
+
<Label Content="承認フロー名:" />
|
88
|
+
<TextBox Grid.Column="1" />
|
89
|
+
</Grid>
|
90
|
+
<ItemsControl ItemsSource="{Binding Items}">
|
91
|
+
|
92
|
+
<!--ItemsPanelが無指定だとStackPanelで縦に並びます-->
|
93
|
+
<!--<ItemsControl.ItemsPanel>
|
94
|
+
<ItemsPanelTemplate>
|
95
|
+
<Canvas />
|
96
|
+
</ItemsPanelTemplate>
|
97
|
+
</ItemsControl.ItemsPanel>-->
|
98
|
+
<ItemsControl.ItemTemplate>
|
99
|
+
<DataTemplate DataType="local:Item">
|
100
|
+
<views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
|
101
|
+
<!--<views:ActionPanel No="{Binding No}" />-->
|
102
|
+
</DataTemplate>
|
103
|
+
</ItemsControl.ItemTemplate>
|
104
|
+
|
105
|
+
<!--ここも必要ないですしItemのXYもいりません-->
|
106
|
+
<!--<ItemsControl.ItemContainerStyle>
|
107
|
+
<Style TargetType="ContentPresenter">
|
108
|
+
<Setter Property="Canvas.Top" Value="{Binding Y}" />
|
109
|
+
<Setter Property="Canvas.Left" Value="{Binding X}" />
|
110
|
+
</Style>
|
111
|
+
</ItemsControl.ItemContainerStyle>-->
|
112
|
+
</ItemsControl>
|
113
|
+
</DockPanel>
|
114
|
+
</DockPanel>
|
115
|
+
</Window>
|
116
116
|
```
|
1
追記 説明&改善例
answer
CHANGED
@@ -41,4 +41,76 @@
|
|
41
41
|
* `_stack`は必要でしょうか?
|
42
42
|
`Items.RemoveAt(Items.Count - 1);`で十分に見えます。
|
43
43
|
* 使っていないあるいは使う必要のない変数
|
44
|
-
`_items`・`_addCommand`等。
|
44
|
+
`_items`・`_addCommand`等。
|
45
|
+
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
追記 説明&改善例
|
50
|
+
|
51
|
+
```xaml
|
52
|
+
<Window
|
53
|
+
x:Class="Questions333961.Views.ApprovalFlowRegist"
|
54
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
55
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
56
|
+
xmlns:local="clr-namespace:Questions333961.ViewModels"
|
57
|
+
xmlns:prism="http://prismlibrary.com/"
|
58
|
+
xmlns:views="clr-namespace:Questions333961.Views"
|
59
|
+
Width="500"
|
60
|
+
Height="360"
|
61
|
+
prism:ViewModelLocator.AutoWireViewModel="True">
|
62
|
+
|
63
|
+
<!--AutoWireViewModel="True"だと、prismが自動的にViewModelを作りWindowのDataContextにセットします-->
|
64
|
+
<!--<Window.Resources>
|
65
|
+
<local:ApprovalFlowRegistViewModel x:Key="ViewModel" />
|
66
|
+
</Window.Resources>-->
|
67
|
+
<!--<DockPanel DataContext="{StaticResource ViewModel}">-->
|
68
|
+
<DockPanel>
|
69
|
+
<StackPanel DockPanel.Dock="Right">
|
70
|
+
<Button
|
71
|
+
MinWidth="90"
|
72
|
+
Margin="10"
|
73
|
+
Command="{Binding AddCommand}"
|
74
|
+
Content="追加" />
|
75
|
+
<Button
|
76
|
+
MinWidth="90"
|
77
|
+
Margin="10"
|
78
|
+
Command="{Binding DelCommand}"
|
79
|
+
Content="削除" />
|
80
|
+
</StackPanel>
|
81
|
+
<DockPanel>
|
82
|
+
<Grid DockPanel.Dock="Top">
|
83
|
+
<Grid.ColumnDefinitions>
|
84
|
+
<ColumnDefinition Width="Auto" />
|
85
|
+
<ColumnDefinition />
|
86
|
+
</Grid.ColumnDefinitions>
|
87
|
+
<Label Content="承認フロー名:" />
|
88
|
+
<TextBox Grid.Column="1" />
|
89
|
+
</Grid>
|
90
|
+
<ItemsControl ItemsSource="{Binding Items}">
|
91
|
+
|
92
|
+
<!--ItemsPanelが無指定だとStackPanelで縦に並びます-->
|
93
|
+
<!--<ItemsControl.ItemsPanel>
|
94
|
+
<ItemsPanelTemplate>
|
95
|
+
<Canvas />
|
96
|
+
</ItemsPanelTemplate>
|
97
|
+
</ItemsControl.ItemsPanel>-->
|
98
|
+
<ItemsControl.ItemTemplate>
|
99
|
+
<DataTemplate DataType="local:Item">
|
100
|
+
<views:ActionPanel No="{Binding DataContext.No, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}" />
|
101
|
+
<!--<views:ActionPanel No="{Binding No}" />-->
|
102
|
+
</DataTemplate>
|
103
|
+
</ItemsControl.ItemTemplate>
|
104
|
+
|
105
|
+
<!--ここも必要ないですしItemのXYもいりません-->
|
106
|
+
<!--<ItemsControl.ItemContainerStyle>
|
107
|
+
<Style TargetType="ContentPresenter">
|
108
|
+
<Setter Property="Canvas.Top" Value="{Binding Y}" />
|
109
|
+
<Setter Property="Canvas.Left" Value="{Binding X}" />
|
110
|
+
</Style>
|
111
|
+
</ItemsControl.ItemContainerStyle>-->
|
112
|
+
</ItemsControl>
|
113
|
+
</DockPanel>
|
114
|
+
</DockPanel>
|
115
|
+
</Window>
|
116
|
+
```
|