【发布时间】:2018-03-10 14:17:47
【问题描述】:
我是 Xamarin.Form 的新手,非常感谢您的帮助。
我正在为我当前的项目使用 MVVM 模式。我的列表视图中填充了人员,我想在列表视图中选择项目并显示详细信息。不幸的是,我找不到任何解决此问题的示例。
这是我的可绑定类:
public static readonly BindableProperty CommandProperty =
BindableProperty.Create(
propertyName: "Command",
returnType: typeof(ICommand),
declaringType: typeof(ListViewItemSelected));
public ICommand Command
{
get { return (ICommand)GetValue(CommandProperty); }
set { SetValue(CommandProperty, value); }
}
protected override void OnAttachedTo(ListView bindable)
{
base.OnAttachedTo(bindable);
bindable.ItemSelected += BindableOnItemSelected;
bindable.BindingContextChanged += BindableOnBindingContextChanged;
}
private void BindableOnBindingContextChanged(object sender, EventArgs e)
{
var lv = sender as ListView;
BindingContext = lv?.BindingContext;
}
private void BindableOnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if (Command == null)
return;
Command.Execute(null);
}
我不确定我的 ViewModel 中的下一步。 我创建了 ICommand 属性来执行该方法
public ICommand DetailView { get; set; }
在我的构造函数中我添加了
DetailView = new Command(PathToDetailView);
我创建了这个方法
void PathToDetailView()
{
//Which I do not know what should go here to redirect to DetailsPage for each item.
}
我有点卡在 DetailViewPage 如何获取值。
感谢您的帮助。
【问题讨论】:
标签: listview xamarin mvvm xamarin.forms