MvvmCross Android - Alternative to RelativeSource binding for button command

♀尐吖头ヾ 提交于 2019-12-24 00:37:40

问题


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

.

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.

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

Can anyone help?


回答1:


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; }
}

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'}}" />    

if you've got suggestions/requests for relative source in mvx, please add them to https://github.com/slodge/MvvmCross/issues/35



来源:https://stackoverflow.com/questions/21591127/mvvmcross-icommand-for-elements-inside-listview-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!