【发布时间】:2018-06-01 01:55:15
【问题描述】:
我正在尝试在页面之间导航并同时绑定数据。
这是我尝试过的:
public ICommand GetIdeasCommand
{
get
{
return new Command(async () =>
{
Ideas = await _apiServices.GetIdeasAsync();
await Application.Current.MainPage.Navigation.PushAsync(new IdeasSinglePage(Ideas));
});
}
}
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' 上有控件吗?
-
我希望视图中填充我从 ` Ideas = await _apiServices.GetIdeasAsync();` @EvZ 获得的信息
-
请分享您的 IdeasSinglePage 代码隐藏和 XAML(如果存在)。 @阿尔多
-
你可以看看我的编辑@EvZ
-
很遗憾,这还不够,您的 IdeasSinglePage 背后的代码在哪里?你如何处理通过的列表?
标签: c# xamarin mvvm binding xamarin.forms