Thursday, January 24, 2013

Data Binding to specific positions/keys in list and dictionary collections in MvvmCross (MonoTouch, MonoDroid, WP, WinRT)

An issue came in recently request we support indexing for databinding - https://github.com/slodge/MvvmCross/issues/110

To support this, we added a new parser for the source property path binding and the end result is lovely.

As a result, the tip of MvvmCross vNext on Mono for Android now supports Array/IList[T]/ObservableCollection[T] indexed bindings like:


And Dictionary[T1,T2] bindings like:

On iOS/MonoTouch those same bindings look like:


If you want to see this in action, check out the 'specific positions' demo on https://github.com/slodge/MvvmCross-Tutorials/tree/master/Collections (some info at http://slodge.blogspot.co.uk/2013/01/work-in-progress-mvvmcross-lists-sample.html)

2 comments:

  1. Great. Works fine.
    One little notice.
    Your sample in Android:
    local:MvxBind="{'Text':{'Path':'Lookup[\\'Felix\\'].Name'}}"
    And iOs:
    "{'Text':{'Path':'Lookup[\"Felix\"].Name'}}"

    on wp7 will look like
    Text='{Binding Path=Lookup[Felix].Name}'

    With no quotes around Felix. It's just a bit nicer, that you don't need to write escaped quotes like \\'

    ReplyDelete
    Replies
    1. If you think it's important, I'm happy for you to fork and fix - https://github.com/slodge/MvvmCross/blob/vnext/Cirrious/Cirrious.MvvmCross.Binding/Parse/PropertyPath/MvxSourcePropertyPathParser.cs

      Delete