私はページ間を移動して同時にデータをバインドしようとしています。mvvmを使用してxamarinフォームでビュー間でデータを渡す
これは私が試したものです:
public ICommand GetIdeasCommand
{
get
{
return new Command(async() =>
{
Ideas = await _apiServices.GetIdeasAsync();
await Application.Current.MainPage.Navigation.PushAsync(new IdeasSinglePage(Ideas));
});
}
}
それは、私は、JSONから入手アレイのリストがあるアイデアを想定しています。しかし、私は空白のページを取得して以来、このアプローチは私を助けていません。また、私はページ内でこの関数を呼び出す場合、すべてが問題ありません。 How to pass a parameter from one Page to another Page in Xamarin.Forms?
マイビュー:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Ideas.Pages.IdeasSinglePage"
xmlns:vm="clr-namespace:Ideas.ViewModel;assembly=Ideas"
Title="My Page">
<ContentPage.BindingContext>
<vm:IdeasViewModel/>
</ContentPage.BindingContext>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="20, 10">
<Label Text="{Binding Ideas}"
FontSize="12"
TextColor="RoyalBlue"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
コードの背後にある:
public partial class IdeasSinglePage : ContentPage
{
public IdeasSinglePage(List<Models.Ideas> ideas)
{
InitializeComponent();
this.BindingContext = new IdeasSinglePage(ideas); //the app breaks here
}
}
おかげ この投稿は、私のアイデアを与えました。
期待される出力は何ですか? 「IdeasSinglePage」にはコントロールがありますか? – EvZ
「Ideas = await _apiServices.GetIdeasAsync(); '@EvZ –
あなたのIdeasSinglePageコードビハインドとXAMLがある場合は、その情報を共有してください。 @Aldo – EvZ