internal static Cell UserCell(PropertyInfo property, IContact context, Page parent = null) { var label = CreateLabel(property); var cell = new TextCell(); cell.BindingContext = parent.BindingContext; cell.SetValue(TextCell.DetailProperty, label); cell.SetBinding( TextCell.TextProperty, new Binding( path: "SelectedModel." + property.Name, mode: BindingMode.OneWay, converter: OwnerConverter, converterParameter: parent.BindingContext ) ); cell.SetValue(TextCell.CommandProperty, new Command(async (a)=>{ var cellTemplate = new DataTemplate(typeof(TextCell)); cellTemplate.SetBinding(TextCell.TextProperty, new Binding(".", converter: OwnerConverter)); var list = new ListView { ItemTemplate = cellTemplate, }; list.SetBinding(ItemsView<Cell>.ItemsSourceProperty, "Users"); list.SetBinding(ListView.SelectedItemProperty, "SelectedModel." + property.Name); list.ItemSelected += async (sender, e)=> { await parent.Navigation.PopAsync(); }; var page = new ContentPage { Title = "Change Owner", Content = list }; page.BindingContext = parent.BindingContext; await parent.Navigation.PushAsync(page); })); return cell; }
internal static Cell UserCell(PropertyInfo property, IContact context, Page parent = null) { var label = CreateLabel(property); var cell = new TextCell(); cell.SetValue(TextCell.TextProperty, label); cell.SetBinding(TextCell.DetailProperty, new Binding(property.Name, converter: OwnerConverter)); cell.SetValue(TextCell.CommandProperty, new Command(async (a)=> { var service = DependencyService.Get<UserRepository>(); var users = await service.All(); var cellTemplate = new DataTemplate(typeof(TextCell)); cellTemplate.SetBinding(TextCell.TextProperty, new Binding(".", converter: OwnerConverter)); var list = new ListView { ItemTemplate = cellTemplate, ItemsSource = users }; list.ItemSelected += async (sender, e)=> { context.Owner = e.SelectedItem as IUser; await parent.Navigation.PopAsync(); }; var page = new ContentPage { Title = "Change Owner", Content = list }; await parent.Navigation.PushAsync(page); })); cell.BindingContext = context; return cell; }