Xamarin Grail的多个Tiles项ClickCommand问题
我已经按照grial grid启用itemClickCommand 以下是源代码DashboardMultipleTimesPage.xaml: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: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;
}
}
}
public ICommand ItemCommand {get; set;}
及
ItemCommand=新命令(ItemAction);
更新:
请确保您已经在
内容页中设置了绑定上下文
,您能解释一下吗,我已经在上面添加了这两行。是的,已经替换了。操作仍然相同,从不执行。共享您的示例,以便我可以在我这边测试它。请发送电子邮件!您可以在github上共享它。
ItemCommand = new Command<DashboardMultipleTilesPage>(ItemAction);