listview - 如何在使用 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>
我可以在我的 ViewModel 中处理点击事件(SelectionChanged)吗?
我应该在我的模板中创建一个按钮,还是这是一个 hack?
解决方案
我没有使用过同步融合控制,但是从文档中它似乎支持基本控制功能。
您可以使用 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
推荐阅读
- python - 为什么我不能在 python repl.it 中使用 PyNaCl 库
- spring-boot - 分别在每个 maven 模块的 ApplicationContext 中运行的中央 SpringBootTest
- django - 如何在我的 django forloop 中使用 if 和 else
- git - 如何删除以前的 git 提交?
- python - 变量 __cached__ 是做什么用的?
- django - Django没有记录任何低于警告的级别
- operating-system - 是否可以从主机访问虚拟机内存而不对虚拟机中的任何进程可见?
- c++ - 如何比较两个对象?
- python - 使用 random.sample,我如何让它打印相邻的字母
- npm - 在 package.json 中执行 bash 脚本