Open SerNikola opened 7 years ago
I discovered that for this to work, I had to move the SelectedItem Command in the Meal class. That's because the ItemsSource for the ListView is the collection of meals.
While this solves my problem, it's far from clean code, or MVVM for that matter. With this solution I am forced to have VM code (Commands) in the Model.
What's the workaround of this?
Is it MVVM friendly to have a ViewModel with an ObservableCollection
Like this:
ViewModels:
public class MainViewModel : FreshBasePageModel
{
public ObservableCollection<OtherViewModel> OtherCollection { get; set; }
}
public class OtherViewModel: FreshBasePageModel
{
public Command SomeCommand { get; set; }
}
And use it like this in the Views:
<ContentPage>
<ListView ItemsSource={Binding OtherCollection} SelectedItem={Binding SomeCommand}>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
This seems Okay to me, but this is my first ever MVVM project, and I wonder if this is how you do stuff.
Thanks a lot for your time,
Hello,
First of all, very nice framework Michael, I enjoy the simplicity of it.
However, I am very new to your framework and Xamarin in general. In fact I am just starting my first project, and for hours I can't bind a Button - or -SelectedItem event on a ListView.
Here is my page, and as you can se it's a carousel page:
`<?xml version="1.0" encoding="utf-8" ?> <CarouselPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="NovTest.Pages.ListDailyMealPlanPage" ItemsSource="{Binding DailyMealPlans}"
Here is a pic for a better view
And here is the PageModel:
The app goes in break mode before the view is rendered. I was wondering, maybe I am doing something completely wrong, like with carousel page binding or I don't know.
Before trying to bind with command/event, all my binds to the properties worked as I expected. Only when I add {Binding SomeCommand} to an element, the app goes in breakmode.
Here is the stack trace for convenience: