c# - Using a toolkit:TouchBehavior LongPressCommandParameter always passes the same parameter to the called function - Stack Ove

When using a press or long press, the corresponding methods are called. However, they always pass the f

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信