我想知道,当你在xml中创建一个MvxListView并使用MvxItemTemplate来描述Items时,有一种方法可以为每一行分配使用的ViewModel(假设有一个)。 我通过扩展我的Item类修复了类似的问题,但是我希望另一个项目是一个AutoCompleteTextView,它的数据列表中填充了提示列表。 我可以将列表输入到IEnumerable中,这只是将列表分配给列表中的每个项目。 我想如果我可以控制每个项目的ViewModel的创建,我可以添加一个包含提示列表并绑定它的属性。
我的主要观点是:
<?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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Mvx.MvxListView android:layout_width="fill_parent" android:layout_height="fill_parent" local:MvxBind="ItemsSource ShipmentInventory.Items" local:MvxItemTemplate="@layout/inventoryitemview" /> <FrameLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/frameLayout2" /> <EditText android:inputType="date" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1" /> </LinearLayout>Item模板的视图是:
<?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:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <MvxSpinner android:layout_width="300dp" android:layout_height="match_parent" android:layout_margin="5dp" android:padding="2dp" local:MvxBind="ItemsSource TagColors; SelectedItem TagColor" android:id="@+id/spinner1" /> <EditText android:layout_width="300dip" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text InventoryNumber" /> <AutoCompleteTextView android:layout_width="300dp" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text Articles; completionHint HintList" /> </LinearLayout>我想如果我可以控制ViewModel用于每个项目,我可以为它添加一个名为HintList的属性。 有没有办法做到这一点?
吉姆
I was wondering if, when you create a MvxListView in xml and use a MvxItemTemplate to describe the Items, there is a way to assign the ViewModel that gets used (assuming there is one) for each line. I fixed a similar problem by extending my Item class, but I want to have another item be an AutoCompleteTextView that has its hint list populated from a database. I can get the list into and IEnumerable, its just a matter of assign that list to to each item in the list. I figure if I can control that creation of the ViewModel for each item, I can add a property that contains the hint list and bind it.
My main View is:
<?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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Mvx.MvxListView android:layout_width="fill_parent" android:layout_height="fill_parent" local:MvxBind="ItemsSource ShipmentInventory.Items" local:MvxItemTemplate="@layout/inventoryitemview" /> <FrameLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/frameLayout2" /> <EditText android:inputType="date" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1" /> </LinearLayout>The view for the Item template is:
<?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:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <MvxSpinner android:layout_width="300dp" android:layout_height="match_parent" android:layout_margin="5dp" android:padding="2dp" local:MvxBind="ItemsSource TagColors; SelectedItem TagColor" android:id="@+id/spinner1" /> <EditText android:layout_width="300dip" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text InventoryNumber" /> <AutoCompleteTextView android:layout_width="300dp" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text Articles; completionHint HintList" /> </LinearLayout>I figure if I can control the ViewModel its using for each item, I can add a property to it called HintList. Is there a way to do this?
Jim
最满意答案
我想出了大部分的细微差别并创造了一个例子
https://github.com/JimWilcox3/MvxAutoCompleteTest
简而言之,当您将数据绑定到MvxItemList时,每个项目的数据模型中的对象充当该项目的ViewModel。 在我的例子中,我刚刚创建了一个项目列表。 如果您正在处理来自WCF的数据,则可以使用分部类扩展在WCF中创建的对象。 在该部分类中,您可以创建MvxCommand以及您可能想要绑定到的其他内容。 希望这有助于某人。
I figured out most of the nuances for this and created an example at
https://github.com/JimWilcox3/MvxAutoCompleteTest
In a nutshell, when you bind data to an MvxItemList, the object in the datamodel for each item acts as your ViewModel for that item. In my example, I just created a list of items. If you are working with data from say WCF, you can extend the object created in the WCF using a partial class. In that partial class you can create MvxCommand and other things that you might want to bind to. Hope this helps someone.
MvvmCross MvxItemTemplate的特定ViewModel,用于填充AutoCompleteTextView(MvvmCross Specific ViewModel for MvxItemTemplate to populate AutoCompleteTextView)我想知道,当你在xml中创建一个MvxListView并使用MvxItemTemplate来描述Items时,有一种方法可以为每一行分配使用的ViewModel(假设有一个)。 我通过扩展我的Item类修复了类似的问题,但是我希望另一个项目是一个AutoCompleteTextView,它的数据列表中填充了提示列表。 我可以将列表输入到IEnumerable中,这只是将列表分配给列表中的每个项目。 我想如果我可以控制每个项目的ViewModel的创建,我可以添加一个包含提示列表并绑定它的属性。
我的主要观点是:
<?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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Mvx.MvxListView android:layout_width="fill_parent" android:layout_height="fill_parent" local:MvxBind="ItemsSource ShipmentInventory.Items" local:MvxItemTemplate="@layout/inventoryitemview" /> <FrameLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/frameLayout2" /> <EditText android:inputType="date" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1" /> </LinearLayout>Item模板的视图是:
<?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:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <MvxSpinner android:layout_width="300dp" android:layout_height="match_parent" android:layout_margin="5dp" android:padding="2dp" local:MvxBind="ItemsSource TagColors; SelectedItem TagColor" android:id="@+id/spinner1" /> <EditText android:layout_width="300dip" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text InventoryNumber" /> <AutoCompleteTextView android:layout_width="300dp" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text Articles; completionHint HintList" /> </LinearLayout>我想如果我可以控制ViewModel用于每个项目,我可以为它添加一个名为HintList的属性。 有没有办法做到这一点?
吉姆
I was wondering if, when you create a MvxListView in xml and use a MvxItemTemplate to describe the Items, there is a way to assign the ViewModel that gets used (assuming there is one) for each line. I fixed a similar problem by extending my Item class, but I want to have another item be an AutoCompleteTextView that has its hint list populated from a database. I can get the list into and IEnumerable, its just a matter of assign that list to to each item in the list. I figure if I can control that creation of the ViewModel for each item, I can add a property that contains the hint list and bind it.
My main View is:
<?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:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Mvx.MvxListView android:layout_width="fill_parent" android:layout_height="fill_parent" local:MvxBind="ItemsSource ShipmentInventory.Items" local:MvxItemTemplate="@layout/inventoryitemview" /> <FrameLayout android:minWidth="25px" android:minHeight="25px" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/frameLayout2" /> <EditText android:inputType="date" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText1" /> </LinearLayout>The view for the Item template is:
<?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:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <MvxSpinner android:layout_width="300dp" android:layout_height="match_parent" android:layout_margin="5dp" android:padding="2dp" local:MvxBind="ItemsSource TagColors; SelectedItem TagColor" android:id="@+id/spinner1" /> <EditText android:layout_width="300dip" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text InventoryNumber" /> <AutoCompleteTextView android:layout_width="300dp" android:layout_height="wrap_content" style="@style/InputEditText" local:MvxBind="Text Articles; completionHint HintList" /> </LinearLayout>I figure if I can control the ViewModel its using for each item, I can add a property to it called HintList. Is there a way to do this?
Jim
最满意答案
我想出了大部分的细微差别并创造了一个例子
https://github.com/JimWilcox3/MvxAutoCompleteTest
简而言之,当您将数据绑定到MvxItemList时,每个项目的数据模型中的对象充当该项目的ViewModel。 在我的例子中,我刚刚创建了一个项目列表。 如果您正在处理来自WCF的数据,则可以使用分部类扩展在WCF中创建的对象。 在该部分类中,您可以创建MvxCommand以及您可能想要绑定到的其他内容。 希望这有助于某人。
I figured out most of the nuances for this and created an example at
https://github.com/JimWilcox3/MvxAutoCompleteTest
In a nutshell, when you bind data to an MvxItemList, the object in the datamodel for each item acts as your ViewModel for that item. In my example, I just created a list of items. If you are working with data from say WCF, you can extend the object created in the WCF using a partial class. In that partial class you can create MvxCommand and other things that you might want to bind to. Hope this helps someone.
发布评论