我試圖在視圖上實現LongClick功能和閱讀其中提供了一些信息 mvvmcross touch command binding in androidmvvmcross自定義綁定到事件處理程序
不成功搜索:IMvxCommand在代碼中如此假設,這可能是過期以下?所以我盡力而爲,但無法獲得任何LongClick功能 - 可能是由於對C#和事件處理程序的瞭解有限。我實現了以下功能,但不確定MvxRelayCommand的用法。
public class LongClickEventBinding: MvxBaseAndroidTargetBinding
{
private readonly View _view;
private MvxRelayCommand<JobJob> _command;
public LongClickEventBinding(View view)
{
_view = view;
_view.LongClick += ViewOnLongClick;
}
private void ViewOnLongClick(object sender, View.LongClickEventArgs eventArgs)
{
if (_command != null)
{
_command.Execute();
}
}
public override void SetValue(object value)
{
_command = (MvxRelayCommand<JobJob>)value;
}
protected override void Dispose(bool isDisposing)
{
if (isDisposing)
{
_view.LongClick -= ViewOnLongClick;
}
base.Dispose(isDisposing);
}
public override Type TargetType
{
get { return typeof(MvxRelayCommand<JobJob>); }
}
public override MvxBindingMode DefaultMode
{
get { return MvxBindingMode.OneWay; }
}
}
而且
protected override void FillTargetFactories(IMvxTargetBindingFactoryRegistry registry)
{
base.FillTargetFactories(registry);
registry.RegisterFactory(new MvxCustomBindingFactory<View>("LongClick", view => new LongClickEventBinding(view)));
}
而且
public ICommand JobSelectedCommand
{
get { return new MvxRelayCommand<JobJob>(NavigateToJobTasks); }
}
public void NavigateToJobTasks(JobJob jobJob)
{
RequestNavigate<JobTaskListViewModel>(new { key = jobJob.JobID });
}
而且
<Mvx.MvxBindableListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="{'ItemsSource':{'Path':'GroupedList'},'LongClick':{'Path':'JobSelectedCommand'}}"
local:MvxItemTemplate="@layout/listitem_job_old"/>
然而,當我在列表項的仿真器和LongClick鼠標按鈕運行的代碼沒有太大的反應。 執行以下操作需要在View
public event EventHandler<View.LongClickEventArgs> LongClick;
任何有助於實現/指針讚賞。
工作的指示。謝謝。 – Kern 2013-02-18 20:45:56