如何解决为什么我们需要为Command设置绑定路径和源xReference,而不仅仅是属性/命令名称?
ListView-> ItemSource = {绑定项} // Works
MenuItem-> Command = {绑定MarkAsCompleted} //不起作用
此仅当我添加路径和源时有效
Command =“ {Binding Path = BindingContext.MarkAsCompletedCommand,Source = {x:Reference TodoViewPage}}”
为什么会这样?!?
<ListView ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Text="Complete" Command="{Binding Path=BindingContext.MarkAsCompletedCommand,Source={x:Reference TodoViewPage}}" CommandParameter="{Binding .}"/>
</ViewCell.ContextActions>
<StackLayout>
<Label Text="{Binding Name}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
解决方法
假设MyCommand
在命名空间MyViewModel
的{{1}}中,请使用MyViewModels
Source
和AncestorType
和RelativeSource
。
在x:Type
和Command
下面的CommandParameter
分别指向Bindings
和MyViewModel
中的项目:
ListView.ItemsSource
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。