本文介绍了MvvmCross vnext:与wp7相似的monodroid绑定字典密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Tutorial.Core中更改MainMenuViewModel来使用像这样的Dictionary时:

When I change MainMenuViewModel in Tutorial.Core to use a Dictionary like this:

`公共词典项目{放; } 公共ICommand ShowItemCommand { 得到 { 返回新的MvxRelayCommand>((type)=> DoShowItem(type.Value)); } }

`public Dictionary Items { get; set; } public ICommand ShowItemCommand { get { return new MvxRelayCommand>((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,我得到一个错误:" MvxBind:Error:2,71在从Items到ItemsSource的绑定执行过程中看到的问题-问题ArgumentException:无法转换参数,因为我认为KeyValuePair Key属性会导致以下问题:

The sample is working as expected in wp7, but with monodroid I get an error::"MvxBind:Error: 2,71 Problem seen during binding execution for from Items to ItemsSource - problem ArgumentException: failed to convert parameters" because I think KeyValuePair Key property causes the problem in:

<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>

预先感谢您的帮助.

推荐答案

问题是mvxbindablelistview需要一个支持IList接口的对象-因此它当前无法绑定到Dictionary.

The problem is that the mvxbindablelistview expects an object that supports the IList interface - so it can't currently bind to a Dictionary.

这就是"ArgumentException:无法转换参数"告诉我们的.

This is what 'ArgumentException: failed to convert parameters' tells us.

如果要使用字典,则可以应用将字典映射到List()的转换器

If you want to use a dictionary, then you could apply a converter that maps the dictionary to a List()

如果您认为这是mvx中缺少的功能-如果您认为列表应该绑定到任何可枚举(或可能绑定到任何icollection)上,请在github上记录此问题.

If you think this is a missing feature in mvx - if you feel lists should bind to any ienumerable (or maybe to any icollection), then please log this is an issue on github.

更新-已在 https://github上进行. com/slodge/MvvmCross/issues/38 -行为现已更改.

Update - this has been pursued on https://github.com/slodge/MvvmCross/issues/38 - and the behavior is now changed.

这篇关于MvvmCross vnext:与wp7相似的monodroid绑定字典密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:35