I'm listing records from my ListItem
tables in my SQLite database in a ListView
, and each record is its own button, which leads to an EditItem
method. All I want to do in this method is set the boolean Large
attribute for the ListItem
to false
, but I'm having trouble getting the corresponding ListItem
as a variable.
With my current code, the error I'm getting is:
Error CS0266 Cannot implicitly convert type 'object' to 'Myapp.Models.ListItem'. An explicit conversion exists (are you missing a cast?)
What's the correct way to get and update the selected record in my code behind?
UPDATE
I tried using a Command with my button, and now I don't get any errors, but the EditItem
method isn't even called. I now know how to pass parameters with the Command
property, but I'm not sure how to call a method with it. I know how to call a method with the Clicked
property, but I don't know how to pass parameters with it.
Xaml:
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Button Text="{Binding Name}" Command="EditItem" CommandParameters="{Binding}" VerticalOptions="Start"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
C# Code Behind:
public async void EditItem(object sender, EventArgs e)
{
ListItem item = (ItemList)sender as ItemList;
item.Large = false;
...
}
I'm using the sqlite-net-pcl Nuget package in a Xamarin.forms app.