MvvmCross机器人 - 替代的RelativeSource绑定按钮命令 [英] MvvmCross Android - Alternative to RelativeSource binding for button command

查看:178
本文介绍了MvvmCross机器人 - 替代的RelativeSource绑定按钮命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

余绑定到与MvxItemTemplate一个MvxBindableListView项的列表。 我通常有4个项目在我绑定到我查看列表。数据得到更新和视图显示新的数据就好了

I have a list of items bound to a MvxBindableListView with a MvxItemTemplate. I usually have 4 items in my list bound to my view. Data gets updated and the view displays the new data just fine.

现在,我想两个按钮添加到该项目模板。不过,相对于源绑定不可用MvvmCross。 (见图片)

Now, I want to add two buttons to this item template. However, relative source binding is not available with MvvmCross. (see image)

但我有困难,制定出一个解决的办法。

But I'm having difficulties working out a solution to this.

我已经试过了列表项的项目单击约束力,但只给了我1可能的点击,我需要2。

I have tried the ItemClick binding of the list item, but that only gives me 1 possibility of click and I need 2.

谁能帮助?

推荐答案

请参阅在回答第二个选项中的<一个href="http://stackoverflow.com/questions/12682082/mvvmcross-changing-viewmodel-within-a-mvxbindablelistview">MVVMCross在一个MvxBindableListView 改变视图模型 - 这包括要做到这一点的方法之一。

See the second option in the answer in MVVMCross changing ViewModel within a MvxBindableListView - this covers one way to do this.

使用这种方法你会暴露就像对象的列表:

Using that approach you'd expose a list of objects like:

public class Wrapped
{
    public ICommand GoThruCommand { get; set; }
    public ICommand OpenCommand { get; set; }
    public string Name { get; set; }
}

和你使用AXML列表模板绑定控件,如:

and you'd use an axml list template with bound controls like:

<TextView
    ...
    local:MvxBind="{'Text':{'Path':'Name'}}" />

<Button
    ...
    local:MvxBind="{'Click':{'Path':'GoCommand'}}" />    

<Button
    ...
    local:MvxBind="{'Click':{'Path':'ThruCommand'}}" />    


如果你有在MVX相对源建议/要求,请把它们添加到的https: //github.com/slodge/MvvmCross/issues/35

这篇关于MvvmCross机器人 - 替代的RelativeSource绑定按钮命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆