When using a press or long press, the corresponding methods are called. However, they always pass the first selected element, regardless of the number of calls. for example, I select category "1", after returning to the category page, no matter which category I select, both for press and long press, category "1" will always be passed.
CategoryViewModel.cs
[ObservableProperty]
private ObservableCollection _categories = new();
[RelayCommand] async Task AddOperation(Category category) { await Shell.Current.GoToAsync(nameof(AddOperationPage), new Dictionary<string, object> { { "choosencategory", category } }); }
Category.xaml
<CollectionView x:Name="collectionView" ItemsSource="{Binding Categories}"
ItemsLayout="VerticalGrid, 2"
SelectedItem="{Binding SelectedCategory}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="models:Category">
<Border BackgroundColor="White"
StrokeShape="RoundRectangle 40"
StrokeThickness="2"
Stroke="{StaticResource Primary}"
Margin="10">
<Grid ColumnDefinitions="0.3*,0.7*" RowDefinitions="0.5*,0.5*">
<Grid.Behaviors>
<toolkit:TouchBehavior Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.AddOperationCommand}"
CommandParameter="{Binding .}"
LongPressDuration="800"
LongPressCommand="{Binding Source={x:Reference collectionView}, Path=BindingContext.ChangeCategoryCommand}"
LongPressCommandParameter="{Binding .}"/>
</Grid.Behaviors>
<Border Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Grid.ColumnSpan="1" Style="{StaticResource BorderCategory}" Padding="10" StrokeThickness="2" Stroke="Black">
<Image Source="{Binding IconPath}" Margin="10">
<Image.Behaviors>
<toolkit:IconTintColorBehavior TintColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Black}}"/>
</Image.Behaviors>
</Image>
</Border>
<Label Grid.Column="1" Grid.Row="0" Text="{Binding Name}" TextColor="Black" HorizontalOptions="Center"/>
<Label Grid.Column="1" Grid.Row="1" Text="{Binding Count}" TextColor="Black" HorizontalOptions="Center"/>
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744293661a4567153.html
评论列表(0条)