如何在ContextActions Xamarin MVVM中设置项目

时间:2017-10-23 10:07:46

标签: c# xamarin mvvm

如何在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; }

现在它不起作用,我不知道为什么

1 个答案:

答案 0 :(得分:1)

请注意,MenuItem的BindingContext是您在ListView的ItemSource中绑定的单一模型,而不是整个ViewModel。您需要使用引用绑定绑定到ViewModel属性,如下所示:

lapply