Reputation: 51255
I have an item template which is to display a List<IGrouping<string, string>>
. In order to do this I need to bind an ItemsSource
to the current binding context, in WPF I would do it something like {Binding DataContext}
how would I do this in MvvmCross?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="Text Key"/> !**IGrouping.Key**!
<Mvx.MvxLinearLayout
android:id="@+id/items"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
local:MvxBind="ItemsSource DataContext" !**This doesn't work, should bind IGrouping as IEnumerable<string>**!
local:MvxItemTemplate="@layout/item_myitem"/>
</LinearLayout>
Upvotes: 1
Views: 742
Reputation: 66882
You can bind to the current source by providing an empty path.
To do this, I find the best syntax is just to use "."
<Mvx.MvxLinearLayout
android:id="@+id/items"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
local:MvxBind="ItemsSource ."
local:MvxItemTemplate="@layout/item_myitem"/>
However, some people prefer using an empty string - although I find this a bit less readable
<Mvx.MvxLinearLayout
android:id="@+id/items"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
local:MvxBind="ItemsSource"
local:MvxItemTemplate="@layout/item_myitem"/>
This option - and lots more besides - is discussed in the data-binding article -
https://github.com/slodge/MvvmCross/wiki/Databinding
(Note: empty string binding was broken in nuget v3.0.9 but should be fixed in v3.0.10 - see Error when making bind ObservableCollection<string> for a MvxListView)
Upvotes: 2