Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin Grail的多个Tiles项ClickCommand问题_Xamarin_Xamarin.forms - Fatal编程技术网

Xamarin Grail的多个Tiles项ClickCommand问题

Xamarin Grail的多个Tiles项ClickCommand问题,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我已经按照grial grid启用itemClickCommand 以下是源代码DashboardMultipleTimesPage.xaml: <grial:GridView WidthRequest="320" Margin="0" Padding="10" ColumnSpacing="10" RowSpacing="10" ItemsSource="{ Binding Items }" ItemClickCommand="{ Binding ItemCommand }" ItemT

我已经按照grial grid启用itemClickCommand

以下是源代码DashboardMultipleTimesPage.xaml:

<grial:GridView
WidthRequest="320"
Margin="0"
Padding="10"
ColumnSpacing="10"
RowSpacing="10"
ItemsSource="{ Binding Items }"
ItemClickCommand="{ Binding ItemCommand }"
ItemTemplate="{ StaticResource Selector }"
ColumnCount="2"/>

下面是Dashboard MultipleTimelesViewModel.cs中的内容

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows.Input;
using UXDivers.Grial;
using Xamarin.Forms;

namespace QlikApps
{
  public class DashboardMultipleTilesViewModel :ObservableObject
  {
     private readonly Command _itemCommand;
     public ICommand ItemCommand => _itemCommand;

     public DashboardMultipleTilesViewModel(): base(listenCultureChanges: true)
     {
     _itemCommand = new Command<DashboardMultipleTilesPage>(ItemAction);
      LoadData();
     }

     public ObservableCollection<DashboardMultipleTileItemData> Items { get; } = new ObservableCollection<DashboardMultipleTileItemData>();


     protected override void OnCultureChanged(CultureInfo culture)
     {
       LoadData();
     }

     private void LoadData()
     {
       Items.Clear();

       JsonHelper.Instance.LoadViewModel(this, source:"NavigationDashboards.json");
}

private void ItemAction(DashboardMultipleTilesPage items)
{
  Application.Current.MainPage.DisplayAlert("Hello", 
    items.Title, "OK");

  string id = items.id; 
}
 }
 }
使用System.Collections.Generic;
使用System.Collections.ObjectModel;
利用制度全球化;
使用System.Windows.Input;
使用UXDivers.Grial;
使用Xamarin.Forms;
名称空间QlikApps
{
公共类仪表板MultipleTimelesViewModel:ObserveObject
{
私有只读命令_itemcond;
公共ICommand itemcond=>\u itemcond;
公用仪表板MultipleTimelesViewModel():基本(ListencCultureChanges:true)
{
_itemCommand=新命令(ItemAction);
LoadData();
}
公共ObservableCollection项{get;}=new ObservableCollection();
受保护的覆盖无效OnCultureChanged(CultureInfo区域性)
{
LoadData();
}
私有void LoadData()
{
Items.Clear();
JsonHelper.Instance.LoadViewModel(来源:NavigationDashboards.json);
}
专用void ItemAction(仪表板多页项)
{
Application.Current.MainPage.DisplayAlert(“你好”,
项目名称,“确定”);
字符串id=items.id;
}
}
}
  • ItemAction(仪表板MultipleTimesPage项目)根本不触发
  • 如何访问当前指向网格的数据
  • 请帮助。

    您可以改进

    public ICommand ItemCommand {get; set;}
    

    ItemCommand=新命令(ItemAction);
    
    更新:
    请确保您已经在
    内容页中设置了
    绑定上下文

    ,您能解释一下吗,我已经在上面添加了这两行。是的,已经替换了。操作仍然相同,从不执行。共享您的示例,以便我可以在我这边测试它。请发送电子邮件!您可以在github上共享它。
    ItemCommand = new Command<DashboardMultipleTilesPage>(ItemAction);