質問編集履歴

1

クラス名と名前空間名の変更

2021/04/30 15:27

投稿

K.KATSU2
K.KATSU2

スコア10

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  ```Xaml
26
26
 
27
- <Window x:Class="ApprovalFlow.Views.ApprovalFlowRegist"
27
+ <Window x:Class="TEST.Views.TESTFlowRegist"
28
28
 
29
29
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
30
30
 
@@ -32,7 +32,7 @@
32
32
 
33
33
  xmlns:prism="http://prismlibrary.com/"
34
34
 
35
- xmlns:views="clr-namespace:ApprovalFlow.Views"
35
+ xmlns:views="clr-namespace:TEST.Views"
36
36
 
37
37
  Height="360" Width="500"
38
38
 
@@ -104,51 +104,73 @@
104
104
 
105
105
 
106
106
 
107
- [windowViewModel]
107
+ [UserControlXaml]
108
+
109
+ ```Xaml
110
+
111
+ <UserControl x:Class="TEST.Views.ActionPanel"
112
+
113
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
114
+
115
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
116
+
117
+ xmlns:prism="http://prismlibrary.com/"
118
+
119
+ Width="340" Height="60"
120
+
121
+ x:Name="panel"
122
+
123
+ prism:ViewModelLocator.AutoWireViewModel="True">
124
+
125
+ <Grid >
126
+
127
+ <TextBlock Text="{Binding No, ElementName=panel}" Margin="2,2,313,35" FontSize="14"/>
128
+
129
+      <!--以下は本ユーザコントロールのViewModelにてバインドし表示-->
130
+
131
+ <ComboBox ItemsSource="{Binding People}" SelectedValue="Value" DisplayMemberPath="DisplayValue"
132
+
133
+ SelectedItem="{Binding SelectedAuthority,Mode=TwoWay}" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="173" Margin="27,0,0,0"/>
134
+
135
+ <ComboBox ItemsSource="{Binding Authority}" SelectedValue="Value" DisplayMemberPath="DisplayValue"
136
+
137
+ SelectedItem="{Binding SelectedAuthority,Mode=TwoWay}" HorizontalAlignment="Left" Margin="210,0,0,0" VerticalAlignment="Top" Width="130" Height="25"/>
138
+
139
+ <Label Content="{Binding Indicator}" HorizontalAlignment="Left" Margin="0,30,0,0" VerticalAlignment="Top" Width="80" Height="30" FontSize="14" FontWeight="Bold" FontFamily="Yu Gothic UI Semibold"/>
140
+
141
+ </Grid>
142
+
143
+ </UserControl>
144
+
145
+ ```
146
+
147
+
148
+
149
+ [UserControlのクラスコード]
108
150
 
109
151
  ```C#
110
152
 
111
- public class ApprovalFlowRegistViewModel : BindableBase
153
+ public partial class ActionPanel : UserControl
112
154
 
113
155
  {
114
156
 
115
- //フィールド
116
-
117
- private static int _xCode=5;
118
-
119
- private int _yCode;
120
-
121
- private int _no;
157
+ public string No
122
-
123
- Stack<Item> _stack;
124
-
125
-
126
-
127
- public ApprovalFlowRegistViewModel()
128
158
 
129
159
  {
130
160
 
131
- _no = 0;
132
-
133
- _yCode = 5;
134
-
135
- _items = new ObservableCollection<Item>();
161
+ get { return (string)this.GetValue(ActionPanel.NoProperty); }
136
-
137
- _stack = new Stack<Item>();
162
+
138
-
139
- AddCommand = new DelegateCommand(ExecuteAddCommand);
140
-
141
- DelCommand = new DelegateCommand(ExecuteDelCommand);
163
+ set { this.SetValue(ActionPanel.NoProperty, value); }
142
164
 
143
165
  }
144
166
 
145
167
 
146
168
 
147
- public string No
169
+ public ActionPanel()
148
170
 
149
171
  {
150
172
 
151
- get { return _no.ToString(); }
173
+ InitializeComponent();
152
174
 
153
175
  }
154
176
 
@@ -156,214 +178,44 @@
156
178
 
157
179
 
158
180
 
181
+ public static readonly DependencyProperty NoProperty = DependencyProperty.Register(
182
+
159
- private ObservableCollection<Item> _items;
183
+ "No",typeof(string),typeof(ActionPanel),
184
+
160
-
185
+ new FrameworkPropertyMetadata("No", new PropertyChangedCallback(OnNoChanged)));
186
+
187
+
188
+
161
- public ObservableCollection<Item> Items
189
+ private static void OnNoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
162
-
190
+
163
- {
191
+ {
192
+
164
-
193
+ ActionPanel ctl = d as ActionPanel; //null checks omitted
194
+
195
+ string s = e.NewValue as string; //null checks omitted
196
+
197
+ if(ctl== null || s == string.Empty)
198
+
199
+ {
200
+
165
- get { return _items; }
201
+ ctl.No = "";
202
+
203
+ }
204
+
205
+ else
206
+
207
+ {
208
+
209
+ ctl.No = s;
210
+
211
+ }
166
212
 
167
213
  }
168
214
 
169
-
170
-
171
- public DelegateCommand AddCommand { get; }
172
-
173
-
174
-
175
- private void ExecuteAddCommand()
176
-
177
- {
178
-
179
- _no++;
180
-
181
- Item itm = new Item( _xCode, _yCode);
182
-
183
- _stack.Push(itm);
184
-
185
- _items.Add(itm);
186
-
187
- _yCode += 60;
188
-
189
- }
190
-
191
-
192
-
193
- public DelegateCommand DelCommand { get; }
194
-
195
-
196
-
197
- private void ExecuteDelCommand()
198
-
199
- {
200
-
201
- if (_no > 0)
202
-
203
- {
204
-
205
- Item itm = _stack.Pop();
206
-
207
- _items.Remove(itm);
208
-
209
- _yCode -= 60;
210
-
211
- _no--;
212
-
213
- }
214
-
215
- else
216
-
217
- {
218
-
219
- MessageBox.Show("これ以上削除できません。");
220
-
221
- }
222
-
223
- }
224
-
225
215
  }
226
216
 
227
-
228
-
229
- public class Item
230
-
231
- {
232
-
233
- public Item(int x, int y)
234
-
235
- {
236
-
237
- X = x;
238
-
239
- Y = y;
240
-
241
- }
242
-
243
- public int X { get; set; }
244
-
245
- public int Y { get; set; }
246
-
247
-
248
-
249
- }
250
-
251
217
  ```
252
218
 
253
-
254
-
255
- [UserControlのXaml]
256
-
257
- ```Xaml
258
-
259
- <UserControl x:Class="ApprovalFlow.Views.ActionPanel"
260
-
261
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
262
-
263
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
264
-
265
- xmlns:prism="http://prismlibrary.com/"
266
-
267
- Width="340" Height="60"
268
-
269
- x:Name="panel"
270
-
271
- prism:ViewModelLocator.AutoWireViewModel="True">
272
-
273
- <Grid >
274
-
275
- <TextBlock Text="{Binding No, ElementName=panel}" Margin="2,2,313,35" FontSize="14"/>
276
-
277
-      <!--以下は本ユーザコントロールのViewModelにてバインドし表示-->
278
-
279
- <ComboBox ItemsSource="{Binding People}" SelectedValue="Value" DisplayMemberPath="DisplayValue"
280
-
281
- SelectedItem="{Binding SelectedAuthority,Mode=TwoWay}" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="173" Margin="27,0,0,0"/>
282
-
283
- <ComboBox ItemsSource="{Binding Authority}" SelectedValue="Value" DisplayMemberPath="DisplayValue"
284
-
285
- SelectedItem="{Binding SelectedAuthority,Mode=TwoWay}" HorizontalAlignment="Left" Margin="210,0,0,0" VerticalAlignment="Top" Width="130" Height="25"/>
286
-
287
- <Label Content="{Binding Indicator}" HorizontalAlignment="Left" Margin="0,30,0,0" VerticalAlignment="Top" Width="80" Height="30" FontSize="14" FontWeight="Bold" FontFamily="Yu Gothic UI Semibold"/>
288
-
289
- </Grid>
290
-
291
- </UserControl>
292
-
293
- ```
294
-
295
-
296
-
297
- [UserControlのクラスコード]
298
-
299
- ```C#
300
-
301
- public partial class ActionPanel : UserControl
302
-
303
- {
304
-
305
- public string No
306
-
307
- {
308
-
309
- get { return (string)this.GetValue(ActionPanel.NoProperty); }
310
-
311
- set { this.SetValue(ActionPanel.NoProperty, value); }
312
-
313
- }
314
-
315
-
316
-
317
- public ActionPanel()
318
-
319
- {
320
-
321
- InitializeComponent();
322
-
323
- }
324
-
325
-
326
-
327
-
328
-
329
- public static readonly DependencyProperty NoProperty = DependencyProperty.Register(
330
-
331
- "No",typeof(string),typeof(ActionPanel),
332
-
333
- new FrameworkPropertyMetadata("No", new PropertyChangedCallback(OnNoChanged)));
334
-
335
-
336
-
337
- private static void OnNoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
338
-
339
- {
340
-
341
- ActionPanel ctl = d as ActionPanel; //null checks omitted
342
-
343
- string s = e.NewValue as string; //null checks omitted
344
-
345
- if(ctl== null || s == string.Empty)
346
-
347
- {
348
-
349
- ctl.No = "";
350
-
351
- }
352
-
353
- else
354
-
355
- {
356
-
357
- ctl.No = s;
358
-
359
- }
360
-
361
- }
362
-
363
- }
364
-
365
- ```
366
-
367
219
  ### 具体的に実現したいこと
368
220
 
369
221