首页 > 解决方案 > 如何在使用 Prism 时将带参数的命令绑定到 Syncfusion Listview...?

问题描述

我正在将 Syncfusion Listview 与 Xamarin 表单一起使用,并希望使用ICommand位于我的模型中的界面。

在阅读此控件的帮助文件时, 它似乎指示我在控件本身上设置一个事件,然后在我的视图中处理响应。

屏幕.xaml

       <syncfusion:SfListView x:Name="listView" Grid.Row="1"  ItemsSource="{Binding TrustAnchors}" 
           SelectionChanged="Handle_SelectionChanged" ItemSize="100" >
            <syncfusion:SfListView.ItemTemplate>
                <DataTemplate>
                    <Grid Padding="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="0.4*" />
                            <RowDefinition Height="0.6*" />
                        </Grid.RowDefinitions>
                        <Label Text="{Binding Name}" FontAttributes="Bold" TextColor="Teal" FontSize="21" />
                        <Label Grid.Row="1" Text="{Binding Description}" TextColor="Teal" FontSize="15"/>
                    </Grid>
                </DataTemplate>
            </syncfusion:SfListView.ItemTemplate>
        </syncfusion:SfListView>

标签: listviewxamarin.formsprismsyncfusionicommand

解决方案


我没有使用过同步融合控制,但是从文档中它似乎支持基本控制功能。

您可以使用 EventToCommandBehavior - https://prismlibrary.github.io/docs/xamarin-forms/EventToCommandBehavior.html

从链接复制:

<ListView>
    <b:EventToCommandBehavior EventName="ItemTapped"
                              Command="{Binding ItemTappedCommand}"
                              EventArgsParameterPath="Item" />
</ListView>

您必须将以下名称空间添加到页面。

xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"

附带说明一下,为什么不使用 DelegateCommand


推荐阅读