2

Cheesebarons 水平リスト ビューを新しい v3 MvvmCross に更新するのに問題があります。私の「BindableHorizo​​ntalListView」コントロールのコンストラクターでアダプターのItemsSourceがnullであることを除いて、すべてが正しく機能しているようです。私がバインドしようとしているview-modelプロパティが3つのアイテムを非常に明確に示しており、バインドが非常に単純であることをコンテキストが示しているため、これは奇妙です。私は何が欠けていますか?十分なコードが含まれていることを願っています。また、「OnViewModelSet」イベントで流暢なバインディングを介してバインドしようとしましたが、同じ結果が得られました。

提示された警告

[MvxBind]  24.87 Unable to bind: source property source not found Cirrious.MvvmCross.Binding.Parse.PropertyPath.PropertyTokens.MvxPropertyNamePropertyToken on DeviceViewModel

AXML

 <BindableHorizontalListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        local:MvxBind="ItemsSource DevicesList; ItemClick ItemSelected"
        local:MvxItemTemplate="@layout/devices_horizontal_list_item" />

BindableHorizo​​ntalListView コントロール

using System.Collections;
using System.Windows.Input;
using Android.Content;
using Android.Util;
using Cirrious.MvvmCross.Binding.Attributes;
using Cirrious.MvvmCross.Binding.Droid.Views;

namespace Project.Droid.Controls
{
    public class BindableHorizontalListView
        : HorizontalListView //Which inherits from AdapterView<BaseAdapter>
    {
        public BindableHorizontalListView(Context context, IAttributeSet attrs) 
            : this(context, attrs, new MvxAdapter(context))
        {
        }

        public BindableHorizontalListView(Context context, IAttributeSet attrs, MvxAdapter adapter)
            : base(context, attrs)
        {
            InitView ();
            var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId (context, attrs);

            adapter.ItemTemplateId = itemTemplateId;
            Adapter = adapter;
            SetupItemClickListener();

        }

        public new MvxAdapter Adapter
        {
            get { return base.Adapter as MvxAdapter; }
            set
            {
                var existing = Adapter;
                if (existing == value)
                    return;

                if (existing != null && value != null)
                {
                    value.ItemsSource = existing.ItemsSource;
                    value.ItemTemplateId = existing.ItemTemplateId;
                }

                base.Adapter = value;
            }
        }

        [MvxSetToNullAfterBinding]
        public IEnumerable ItemsSource
        {
            get { return Adapter.ItemsSource; }
            set { Adapter.ItemsSource = value; this.Reset (); }
        }

        public int ItemTemplateId
        {
            get { return Adapter.ItemTemplateId; }
            set { Adapter.ItemTemplateId = value; }
        }

        public new ICommand ItemClick { get; set; }

        private void SetupItemClickListener()
        {
            base.ItemClick += (sender, args) =>
            {
                if (null == ItemClick)
                    return;
                var item = Adapter.GetItem(args.Position) as Java.Lang.Object;
                if (item == null)
                    return;

                if (item == null)
                    return;

                if (!ItemClick.CanExecute(item))
                    return;

                ItemClick.Execute(item);
            };
        }
    }
}

意見

[Activity (Label = "Device", ScreenOrientation = ScreenOrientation.Portrait)]
public class DeviceView : MvxActivity
{

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        SetContentView(Resource.Layout.device);
    }

}

ViewModel のプロパティ

private Services.Device[] _devicesList;
public Services.Device[] DevicesList {
    get {
        return _devicesList;
    }
    set {
        _devicesList = value;
        RaisePropertyChanged(() => DevicesList);
    }
}

XAM STUDIO で PCL がサポートされていれば、他のコントロールがどのように機能しているかを確認するだけです!!!!

4

1 に答える 1

2

コンストラクターでは ItemsSource は常に空になります。これはバインディングによって設定されるプロパティであり、そのプロパティはコンストラクターが完了した後にのみ設定できます。

メッセージ:

[MvxBind]  24.87 Unable to bind: source property source not found Cirrious.MvvmCross.Binding.Parse.PropertyPath.PropertyTokens.MvxPropertyNamePropertyToken on DeviceViewModel

最近のコミットで修正されたバグが含まれているため、メッセージは将来的に読みやすくなるはずです。

バグがそこになかった場合、メッセージは問題があることを示していると思いますDevicesList-バインディングはそのプロパティを見つけることができません. そこにいますか?それはありgetますか?ですかpublic

于 2013-09-01T20:22:41.257 に答える