如何在ContextActions中设置项目。在我的例子中,我想设置默认汽车。
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Text="Ustaw domyslny" Command="{Binding DefultCarCommand}" CommandParameter="{Binding .}"/>
</ViewCell.ContextActions>
<StackLayout>
<Label Text="{Binding RegistrationNumber}" />
<Label Text="{Binding Brand}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
在ViewModel中,我使用DelegateCommand
public DelegateCommand DefultCarCommand { get; private set; }
现在它不起作用,我不知道为什么
答案 0 :(得分:1)
请注意,MenuItem的BindingContext是您在ListView的ItemSource中绑定的单一模型,而不是整个ViewModel。您需要使用引用绑定绑定到ViewModel属性,如下所示:
lapply