Bind item object in ItemTemplate in MVVMCross
-
26-12-2019 - |
Question
I am developing an MVVMCross multi platform app and I'm having the following trouble with Converters:
I have a listView in Android with the following code:
<MyProjectName.Droid.MvxCustomViews.MvxListView.MvxDroidListView
android:id="@+id/historicList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:listSelector="#00000000"
android:fadingEdge="none"
local:MvxBind="ItemsSource Historics;"
local:MvxItemTemplate="@layout/historiclistitem" />
Where, Historics is a List. Then, I have in the layout resource:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal">
<ImageView
android:id="@+id/historicIcon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:layout_gravity="center"
local:MvxBind="AssetImagePath UpdateType, Converter=HistoricTypeToSource" />
<TextView
android:id="@+id/listHistoricType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Anexo"
android:textColor="#0000FF"
android:textSize="16sp"
android:layout_gravity="center"
local:MvxBind="Text UpdateType, Converter=HistoricTypeToString" />
</LinearLayout>
<TextView
android:id="@+id/listHistoricTypeDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anexo adicionado"
android:textColor="#000000"
local:MvxBind="Text ???, Converter=HistoricDetailsToString" />
The problem is, everything is working fine, but in the listHistoricTypeDetail's TextView's bind I need to pass the entire object, because, depending on each Historic.Action, I will add a text that uses Historic.AdditionalParameter, Historic.NewValue, Historic.OldValue!!!
I'm not figuring out how to pass 3 parameters depending on the value of the bind to the converter, or how to bind the entire object so my converter would be like: MyConverter : MvxValueConverter
Is that clear? Can anyone help me?
Thanks in regards,
Solution
Given the complexity of your conversion, I think it's probably easiest to pass the entire object which you can do just by using a single period:
local:MvxBind="Text ., Converter=HistoricDetailsToString"
or - using Tibet-syntax - as:
local:MvxBind="Text HistoricDetailsToString(.)"
I think the wiki article may also help: https://github.com/MvvmCross/MvvmCross/wiki/Databinding
e.g.:
If
$SourcePath$
is omitted or a single period "." is used, then the Source used is the whole of the ViewModel.
from https://github.com/MvvmCross/MvvmCross/wiki/Databinding#swiss