回答編集履歴
2
コード修正
answer
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
{
|
|
16
16
|
InitializeComponent();
|
|
17
17
|
|
|
18
|
+
var navigationService = ((IContainerExtension)PrismApplicationBase.Current.Container).CreateNavigationService(this);
|
|
18
|
-
BindingContext = PrismApplicationBase.Current.Container.Resolve<ViewModels.MainPageViewModel>();
|
|
19
|
+
BindingContext = PrismApplicationBase.Current.Container.Resolve<ViewModels.MainPageViewModel>((typeof(INavigationService), navigationService));
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
}
|
1
自前の作成方法の追記
answer
CHANGED
|
@@ -1,1 +1,22 @@
|
|
|
1
|
-
Prismが自動でViewModelを作成するので、自分でnewして`BindingContext`に代入する必要はありません。自動作成の際に、Unityを利用して、コンストラクタに引数が渡されます。
|
|
1
|
+
Prismが自動でViewModelを作成するので、自分でnewして`BindingContext`に代入する必要はありません。自動作成の際に、Unityを利用して、コンストラクタに引数が渡されます。
|
|
2
|
+
一応、以下のようにすれば、自分で作成することもできます。
|
|
3
|
+
|
|
4
|
+
```C#
|
|
5
|
+
using PrismTest.Model;
|
|
6
|
+
using Xamarin.Forms;
|
|
7
|
+
using Prism;
|
|
8
|
+
using Prism.Ioc;
|
|
9
|
+
|
|
10
|
+
namespace PrismTest.Views
|
|
11
|
+
{
|
|
12
|
+
public partial class MainPage : ContentPage
|
|
13
|
+
{
|
|
14
|
+
public MainPage()
|
|
15
|
+
{
|
|
16
|
+
InitializeComponent();
|
|
17
|
+
|
|
18
|
+
BindingContext = PrismApplicationBase.Current.Container.Resolve<ViewModels.MainPageViewModel>();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|