根据您的代码,我创建了一个简单的演示,它可以正常工作。
您可以参考以下代码:
<ListView ItemsSource="{Binding items}" HasUnevenRows="True" HeightRequest="240" x:Name="Listview">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame Padding="0" >
<Grid Padding="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
<ColumnDefinition Width="3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label x:Name="DistNumber" Text="{Binding DistNumber}" FontSize="18" Grid.Column="1" HorizontalTextAlignment="Start" VerticalOptions="Center"/>
<Entry x:Name="CountEntry" Placeholder="Choose Quantity"
Text="{Binding Count}"
Grid.Column="2" HorizontalTextAlignment="Center" >
<Entry.Behaviors>
<behaviors:EventToCommandBehavior
EventName="Unfocused"
Command="{Binding Path=BindingContext.EntryUnfocused, Source={x:Reference Listview}}" CommandParameter="{Binding .}" />
</Entry.Behaviors>
</Entry>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
视图模型是:
public class MyViewModel
{
public ObservableCollection<SomeItem> items { get; set; }
public ICommand EntryUnfocused { get; protected set; }
public MyViewModel() {
items = new ObservableCollection<SomeItem>();
items.Add(new SomeItem { Name = "item1", DistNumber = "1", Count = 1,Quantity = 1 });
items.Add(new SomeItem { Name = "item2", DistNumber = "2", Count = 2, Quantity = 2 });
items.Add(new SomeItem { Name = "item3", DistNumber = "3", Count = 3, Quantity = 3 });
items.Add(new SomeItem { Name = "item4", DistNumber = "4", Count = 4, Quantity = 4 });
items.Add(new SomeItem { Name = "item5", DistNumber = "5", Count = 5, Quantity = 5 });
items.Add(new SomeItem { Name = "item6", DistNumber = "6", Count = 6, Quantity = 6 });
EntryUnfocused = new Command(CompletedCommandExecutedAsync);
}
private void CompletedCommandExecutedAsync(Object obj)
{
SomeItem item = (SomeItem)obj;
System.Diagnostics.Debug.WriteLine("<----- item Name = " + item.Name + "<-----> item Count = " + item.Count);
}
}