本文介绍了MvvmCross Android - 按钮命令的 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.

我已经尝试了列表项的 ItemClick 绑定,但这只给了我 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.

有人可以帮忙吗?

推荐答案

MVVMCross 在 MvxBindableListView 中更改 ViewModel - 这涵盖了一种方法.

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 Android - 按钮命令的 RelativeSource 绑定的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 07:41