Xamarin.formsでMainPageに設置したEntryに入力された値をSecondPageで受け取りたいのですがうまくいきません。
Prism for Xamarin.forms(6.3)を導入しています。
MainPageViewModel.cs
C#
1public class MainPageViewModel : BindbleBase, INavigationAware 2{ 3 private string _keyWord; 4 public string KeyWord 5 { 6 get { return _keyWord; } 7 set { SetProperty(ref _keyWord, value); } 8 } 9 public DelegateCommand NavigateSecondCommand { get; private set; } 10 11 private readonly INavigationService _navigationService; 12 13 public MainPageViewModel(INavigationService navigationService) 14 { 15 _navigationService = navigationService; 16 NavigateSecondCommand = new DelegateCommand(() => 17 { 18 var navigationParameters = new NavigationParameters(); 19 navigationParameters.Add("KeyWord", KeyWord); 20 _navigationService.NavigateAsync("SecondPage", navigationParameters); 21 }); 22 } 23}
MainPage.xaml
XAML
1<StackLayout HorizontalOptions="Center" VerticalOptions="Center"> 2 <Entry Text="{Binding KeyWord}" /> 3 <Button Text="NEXT" Command={Binding NavigateSecondCommand} /> 4</StackLayout>
SecondPageViewModel.cs
C#
1public class SecondPageViewModel : BindbleBase, INavigationAware 2{ 3 private string _keyWord; 4 public string KeyWord 5 { 6 get{ return _keyWord; } 7 set{ SetPropety(ref _keyWord, value); } 8 } 9 10 public SecondPageViewModel() 11 { 12 } 13 14 public void OnNavigatedTo(NavigationParameters parameters) 15 { 16 if(parameters.containsKey("KeyWord")) 17 { 18 KeyWord = parameters["KeyWord"] as string; 19 } 20 } 21}
SecondPage.xaml
xaml
1<StackLayout HorizontalOptions="Center" VerticalOptions="Center"> 2 <Label Text="{Binding KeyWord}" /> 3</StackLayout>
AndroidでビルドするとSecondPageのラベルにMainPageで入力された値が表示されません。
どこが間違っているのかわかりません。ご教示ください。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。