質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

Q&A

解決済

1回答

4286閲覧

Xamarin.formsの画面遷移時のパラメーターの受け渡し

KirisimaCreate

総合スコア44

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

XAML

XAML(Extensible Application Markup Language)はWPF、Silverlight、Windows PhoneそしてWindows Store appsでユーザーインターフェースを定義するために使われるXML言語です。

Xamarin

Xamarin(ザマリン)は、iPhoneなどのiOSやAndroidで動作し、C# 言語を用いてアプリを開発できるクロスプラットフォーム開発環境です。Xamarin Studioと C# 言語を用いて、 iOS と Android の両方の開発を行うことができます。

0グッド

0クリップ

投稿2017/11/14 15:01

編集2017/11/15 02:49

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で入力された値が表示されません。
どこが間違っているのかわかりません。ご教示ください。
よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

自己解決しました。
XAMLのButtonタグにCommandParameter要素を追加するとパラメーターの受け渡しができました。

MainPage.xaml

XAML

1<StackLayout HorizontalOptions="Center" VerticalOptions="Center"> 2 <Entry Text="{Binding KeyWord}" /> 3 <Button Text="NEXT" Command={Binding NavigateSecondCommand} 4 CommandParameter={Binding KeyWord}/> 5</StackLayout>

投稿2017/11/14 19:21

KirisimaCreate

総合スコア44

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問