我從教程樣品MainMenuView使用,而不是列表的字典。在WP7,我綁定是這樣的:MvvmCross vnext:MonoDroid的CommandParameter類似WP7
<ListBox ItemsSource="{Binding Items}" x:Name="TheListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Key}" Margin="12" FontSize="24" TextWrapping="Wrap">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<commandbinding:MvxEventToCommand Command="{Binding Path=DataContext.ShowItemCommand, ElementName=TheListBox}" CommandParameter="{Binding Value}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
但隨着MonoDroid的,我不知道放在哪裏CommandParameter = 「{綁定值}」 在mvxListView,我得到這個錯誤:「MvxBind:錯誤:2, 71問題從項目到綁定的ItemsSource執行過程中看到的 - 問題的ArgumentException:未能參數從我axml代碼轉換」:
<Mvx.MvxBindableListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Tutorial.UI.Droid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="{'ItemsSource':{'Path':'Items'},'ItemClick':{'Path':'ShowItemCommand'}}"
local:MvxItemTemplate="@layout/listitem_viewmodel"
/>
如何設置一個CommandParameter財產在WP7?
在此先感謝您的幫助。
按照你的指令1,我改變MainMenuViewModel在Tutorial.Core這樣的:
'公共字典項{獲得;組; }
public ICommand ShowItemCommand
{
get
{
return new MvxRelayCommand<KeyValuePair<string, Type>>((type) => DoShowItem(type.Value));
}
}
public void DoShowItem(Type itemType)
{
this.RequestNavigate(itemType);
}
public MainMenuViewModel()
{
Items = new Dictionary<string, Type>()
{
{"SimpleTextProperty", typeof(Lessons.SimpleTextPropertyViewModel)},
{"PullToRefresh", typeof(Lessons.PullToRefreshViewModel)},
{"Tip", typeof(Lessons.TipViewModel)},
{"Composite",typeof(Lessons.CompositeViewModel)},
{"Location",typeof(Lessons.LocationViewModel)}
};
}`
樣品正按預期在WP7,但MonoDroid的我得到同樣的錯誤與前一個,因爲我覺得KeyValuePair主要財產造成的問題:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Tutorial.UI.Droid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="View Model:"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
local:MvxBind="{'Text':{'Path':'Key'}}"
/>
</LinearLayout>
我更新了我的問題,因爲我得到了同樣的錯誤。 – Alphapage
我提出了這裏的問題:http://stackoverflow.com/questions/12899593/mvvmcross-vnext-monodroid-binding-dictionary-key-similar-to-wp7 – Alphapage