gpt4 book ai didi

c# - ItemsSource 在 Custom Bound Horizo​​ntal ScrollView 的构造函数中为空

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:35 25 4
gpt4 key购买 nike

我在将 Cheesebarons 水平 ListView 更新到新的 v3 MvvmCross 时遇到问题。一切似乎都正常工作,除了在我的“BindableHorizo​​ntalListView”控件的构造函数中,适配器的 ItemsSource 为空。这很奇怪,因为上下文显示我试图绑定(bind)的 View 模型属性非常清楚地显示有 3 个项目,绑定(bind)看起来非常简单。我错过了什么?我希望我已经包含了足够多的代码。我还尝试通过对“OnViewModelSet”事件的流畅绑定(bind)来绑定(bind)它,结果相同。

出现警告

[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 支持就好了,我会介入看看其他控件是怎么做的!!!!

最佳答案

ItemsSource 在构造函数中将始终为空 - 它是一个通过绑定(bind)设置的属性,并且该属性只能在构造函数完成后设置。

讯息:

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

包含错误 - 已在 a recent commit 中修复- 因此消息在未来应该更具可读性。

如果错误不存在,我怀疑消息会说问题出在 DevicesList 中 - 绑定(bind)无法找到该属性。它在那里吗?它有 get 吗?它是 public 吗?

关于c# - ItemsSource 在 Custom Bound Horizo​​ntal ScrollView 的构造函数中为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18554755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com