回答編集履歴

1

見直しキャンペーン中

2023/07/28 13:42

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -1,257 +1,118 @@
1
- ```C#
1
+ ```cs
2
-
3
2
  //containerRegistry.RegisterInstance<IDateTime>(new DateTimeModel());
4
-
5
3
  containerRegistry.Register<IDateTime, DateTimeModel>();
6
-
7
4
  ```
8
-
9
5
  `Register`でいいことを確認しました。
10
-
11
-
12
6
 
13
7
  ---
14
8
 
15
-
16
-
17
9
  `Prism Full App`ベースで記載のないものはデフォルト。
18
10
 
19
-
20
-
21
11
  `DrInfoView`(`InfoView`どっちなの?)等不明な部分はオミット。
22
-
23
12
  `DateTimeModel`等で確認に不要な部分もばっさりカット。
24
13
 
25
-
26
-
27
- Questions348165
14
+ ### Questions348165
28
-
29
- Views.MainWindow.xaml
15
+ ```xml:Views.MainWindow.xaml
30
-
31
- ```xaml
32
-
33
16
  <Window
34
-
35
17
  x:Class="Questions348165.Views.MainWindow"
36
-
37
18
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
38
-
39
19
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
40
-
41
20
  xmlns:prism="http://prismlibrary.com/"
42
-
43
21
  Width="525"
44
-
45
22
  Height="350"
46
-
47
23
  prism:ViewModelLocator.AutoWireViewModel="True">
48
-
49
24
  <StackPanel Orientation="Horizontal">
50
-
51
25
  <ContentControl prism:RegionManager.RegionName="DateTime" />
52
-
53
26
  <ContentControl prism:RegionManager.RegionName="DateTime2" />
54
-
55
27
  </StackPanel>
56
-
57
28
  </Window>
58
-
59
29
  ```
60
-
61
-
62
-
63
- Questions348165.Modules.ModuleName
64
-
65
- Views.DateTimeView.xaml
66
-
67
- ```xaml
68
-
69
- <UserControl
70
-
71
- x:Class="Questions348165.Modules.ModuleName.Views.DateTimeView"
72
-
73
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
74
-
75
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
76
-
77
- xmlns:prism="http://prismlibrary.com/"
78
-
79
- prism:ViewModelLocator.AutoWireViewModel="True">
80
-
81
- <StackPanel>
82
-
83
- <TextBlock Text="No" />
84
-
85
- <TextBlock Text="{Binding No}" />
86
-
87
- </StackPanel>
88
-
89
- </UserControl>
90
-
91
- ```
92
-
93
-
94
-
95
- Questions348165
96
-
97
- App.xaml.cs
30
+ ```cs:App.xaml.cs
98
-
99
- ```C#
100
-
101
31
  using Prism.Ioc;
102
-
103
32
  using Prism.Modularity;
104
-
105
33
  using Questions348165.Modules.ModuleName;
106
-
107
34
  using Questions348165.Views;
108
-
109
35
  using System.Windows;
110
36
 
111
-
112
-
113
37
  namespace Questions348165
114
-
115
38
  {
116
-
117
39
  public partial class App
118
-
119
40
  {
120
-
121
41
  protected override Window CreateShell() => Container.Resolve<MainWindow>();
122
-
123
-
124
42
 
125
43
  protected override void RegisterTypes(IContainerRegistry containerRegistry) { }
126
44
 
45
+ protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
46
+ => moduleCatalog.AddModule<DateTimeModule>();
47
+ }
48
+ }
49
+ ```
127
50
 
51
+ ### Questions348165.Modules.ModuleName
52
+ ```xml:Views.DateTimeView.xaml
53
+ <UserControl
54
+ x:Class="Questions348165.Modules.ModuleName.Views.DateTimeView"
55
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
56
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
57
+ xmlns:prism="http://prismlibrary.com/"
58
+ prism:ViewModelLocator.AutoWireViewModel="True">
59
+ <StackPanel>
60
+ <TextBlock Text="No" />
61
+ <TextBlock Text="{Binding No}" />
62
+ </StackPanel>
63
+ </UserControl>
64
+ ```
65
+ ```cs:DateTimeModule.cs
66
+ using Prism.Ioc;
67
+ using Prism.Modularity;
68
+ using Prism.Regions;
128
69
 
70
+ namespace Questions348165.Modules.ModuleName
71
+ {
72
+ public class DateTimeModule : IModule
73
+ {
129
- protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
74
+ public void OnInitialized(IContainerProvider containerProvider)
75
+ {
76
+ var regionMan = containerProvider.Resolve<IRegionManager>();
77
+ regionMan.RegisterViewWithRegion("DateTime", typeof(Views.DateTimeView));
78
+ regionMan.RegisterViewWithRegion("DateTime2", typeof(Views.DateTimeView));
79
+ }
130
80
 
81
+ public void RegisterTypes(IContainerRegistry containerRegistry)
82
+ {
83
+ //containerRegistry.RegisterInstance<IDateTime>(new DateTimeModel());
131
- => moduleCatalog.AddModule<DateTimeModule>();
84
+ containerRegistry.Register<IDateTime, DateTimeModel>();
132
-
85
+ }
133
86
  }
134
87
 
135
- }
136
-
137
- ```
138
-
139
-
140
-
141
- Questions348165.Modules.ModuleName
142
-
143
- DateTimeModule.cs
144
-
145
- ```C#
146
-
147
- using Prism.Ioc;
148
-
149
- using Prism.Modularity;
150
-
151
- using Prism.Regions;
152
-
153
-
154
-
155
- namespace Questions348165.Modules.ModuleName
156
-
157
- {
158
-
159
- public class DateTimeModule : IModule
88
+ public interface IDateTime
160
-
161
89
  {
162
-
163
- public void OnInitialized(IContainerProvider containerProvider)
164
-
165
- {
166
-
167
- var regionMan = containerProvider.Resolve<IRegionManager>();
168
-
169
- regionMan.RegisterViewWithRegion("DateTime", typeof(Views.DateTimeView));
170
-
171
- regionMan.RegisterViewWithRegion("DateTime2", typeof(Views.DateTimeView));
172
-
173
- }
174
-
175
-
176
-
177
- public void RegisterTypes(IContainerRegistry containerRegistry)
90
+ public int No { get; }
178
-
179
- {
180
-
181
- //containerRegistry.RegisterInstance<IDateTime>(new DateTimeModel());
182
-
183
- containerRegistry.Register<IDateTime, DateTimeModel>();
184
-
185
- }
186
-
187
91
  }
188
92
 
189
-
190
-
191
- public interface IDateTime
93
+ public class DateTimeModel : IDateTime
192
-
193
94
  {
194
-
195
95
  public int No { get; }
196
-
197
- }
198
-
199
-
200
-
201
- public class DateTimeModel : IDateTime
202
-
203
- {
204
-
205
- public int No { get; }
206
-
207
96
  private static int no;
208
97
 
209
-
210
-
211
98
  public DateTimeModel() => No = ++no;
212
-
213
99
  }
214
-
215
100
  }
216
-
217
101
  ```
218
-
219
-
220
-
221
- Questions348165.Modules.ModuleName
222
-
223
- ViewModels.DateTimeViewModel.cs
102
+ ```cs:ViewModels.DateTimeViewModel.cs
224
-
225
- ```C#
226
-
227
103
  using Prism.Mvvm;
228
104
 
229
-
230
-
231
105
  namespace Questions348165.Modules.ModuleName.ViewModels
232
-
233
106
  {
234
-
235
107
  public class DateTimeViewModel : BindableBase
236
-
237
108
  {
238
-
239
109
  IDateTime DateTime;
240
-
241
110
  public int No => DateTime.No;
242
111
 
243
-
244
-
245
112
  public DateTimeViewModel(IDateTime dateTime)
246
-
247
113
  {
248
-
249
114
  DateTime = dateTime;
250
-
251
115
  }
252
-
253
116
  }
254
-
255
117
  }
256
-
257
118
  ```