ListView上下文菜单上的命令绑定未触发(未找到)?

时间:2018-12-26 13:00:52

标签: c# xamarin mvvm command

我在ListView上遇到绑定问题,出现错误:

Binding: 'OnEdit' property not found on 'ContactsViewModel', target property: 'Xamarin.Forms.MenuItem.Command'

这是XAML(也许我在引用中犯了一个错误):

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Contactium.ContactsPage"
         x:Name="ContactsPageContent">
<ContentPage.ToolbarItems>
...
<TextCell.ContextActions>
      <MenuItem  Command="{Binding Path=BindingContext.OnEdit, Source={x:Reference ContactsPageContent}}" CommandParameter="{Binding .}" Text="EDITER" IsDestructive="True"/>
      <MenuItem Command="{Binding Path=BindingContext.OnDelete, Source={x:Reference ContactsPageContent}}}" CommandParameter="{Binding .}" Text="SUPPRIMER"/>
</TextCell.ContextActions>
...

这是ViewModel(ContactsPageContent):

public Command OnEdit(object sender, EventArgs e)
{
    return new Command(() =>
    {
         Debug.Write("OK");
    });
}

public Command OnDelete(object sender, EventArgs e)
{
    return new Command(() =>
    {
         Debug.Write("OK");
    });
}

谢谢您的时间!

2 个答案:

答案 0 :(得分:0)

以下面的属性形式编写您的Your connection is not private Attackers might be trying to steal your information from votes.nilov-sergey-demo-apps.tk (for example, passwords, messages, or credit cards). Learn more NET::ERR_CERT_COMMON_NAME_INVALID

Command

答案 1 :(得分:0)

<ListView x:Name="Cities" <ListView.ItemTemplate>
  <DataTemplate>
    <ViewCell>
      <ViewCell.ContextActions>

        <MenuItem Command="{Binding Path=BindingContext.DeleteCommand ,Source={x:Reference Name=Cities}}" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True">

        </MenuItem>

      </ViewCell.ContextActions>

在您的ViewModel中,您可以使用以下代码:

DeleteCommand = new Command<Category>(async (selected) =>
            {});