我试图添加一个Clickable ListView-Cell,但可能与绑定发生冲突。
每个单元格应该像一个导航到包含给定对象的新页面的按钮。 我已经尝试过使用“ TapGestureRecognizer”。
<ListView x:Name="ListView" HasUnevenRows="True" SelectionMode="Single" >
<ListView.ItemsSource>
<x:Array Type="{x:Type clients:MinRepresentation}">
<clients:MinRepresentation Id="123456789" PlannedStartTime="01-01-2019" PlannedEndTime="01-12-2019" />
<clients:MinRepresentation Id="555555555" PlannedStartTime="12-12-2019" PlannedEndTime="12-12-2019" />
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="5">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OrderDetailsCommand}"/>
</Grid.GestureRecognizers>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
[Cell-Template]
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:0)
得到了简单的解决方案...
XAML:
<ListView HasUnevenRows="True" SelectionMode="Single" ItemsSource="{Binding VisibleOrders}" ItemSelected="OnListViewItemSelected" ItemTapped="OnListViewItemTapped"/>
ViewModel:
public IList<MinRepresentation> VisibleOrders { get; private set; }
void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs e)
{
MinRepresentation selectedItem = e.SelectedItem as MinRepresentation;
}
void OnListViewItemTapped(object sender, ItemTappedEventArgs e)
{
MinRepresentation tappedItem = e.Item as MinRepresentation;
}