public DetailView (DetailViewModel vm) { InitializeComponent (); // TODO: AO. Enlazar el ViewModel con la vista a partir del BindingContext }
public DetailView (DetailViewModel vm) { InitializeComponent (); BindingContext = vm; }
public FirstView() { InitializeComponent(); //var image = new Image() //{ // HeightRequest = 80, // WidthRequest = 80 //}; //image.SetBinding(Image.SourceProperty, "Thumbnail"); //var label = new Label() //{ // VerticalTextAlignment = TextAlignment.Start, // HorizontalTextAlignment = TextAlignment.Start, // VerticalOptions = LayoutOptions.FillAndExpand, // HorizontalOptions = LayoutOptions.FillAndExpand //}; //label.SetBinding(Label.TextProperty, "Name"); //var stack = new StackLayout() //{ // Orientation = StackOrientation.Horizontal //}; //stack.Children.Add(image); //stack.Children.Add(label); //var dt = new DataTemplate(() => //{ // return new ViewCell() // { // View = stack // }; //}); // var dt = new DataTemplate(typeof(ImageCell)); // dt.SetBinding(ImageCell.ImageSourceProperty, "Thumbnail"); // dt.SetBinding(ImageCell.TextProperty, "Name"); // Navigation to detail page this.listCharacters.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => { var character = (CharacterItemViewModel)e.SelectedItem; var detailVm = new DetailViewModel(character); var detailView = new DetailView(detailVm); this.Navigation.PushAsync(detailView); }; Device.OnPlatform(WinPhone: () => listCharacters.ItemTemplate = new DataTemplate(() => { var nativeCell = new NativeCell(); nativeCell.SetBinding(NativeCell.NameProperty, "Name"); nativeCell.SetBinding(NativeCell.ThumbnailProperty, "Thumbnail"); return nativeCell; })); // listCharacters.ItemTemplate = dt; // // listCharacters.SetBinding(ListView.ItemsSourceProperty, new Binding("CharacterList")); _vm = new FirstViewModel(); BindingContext = _vm; _vm.LoadData(); }