- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 fragment 中使用了 MvxRecyclerView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="My Headline" />
<MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView
android:id="@+id/RecyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Headline"
android:layout_marginTop="50dp" />
</RelativeLayout>
这是 fragment 代码:
[MvxFragment(typeof(MainViewModel), Resource.Id.Main_ViewPager)]
[Register("my.app.fragments.MyFragment")]
public class MyFragment : BaseFragment<MyViewModel>
{
private MvxRecyclerView recyclerView;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.MyFragment, null);
this.recyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.RecyclerView);
this.recyclerView.ItemTemplateId = Resource.Layout.MyCell;
var set = this.CreateBindingSet<MyFragment, MyViewModel>();
set.Bind(this.recyclerView).For(x => x.ItemsSource).To(x => x.Items);
set.Apply();
return view;
}
}
还有 ViewModel:
public class MyViewModel : MvxViewModel
{
....
private ObservableCollection<T> items;
public ObservableCollection<T> Items
{
get { return this.items; }
set
{
this.items = value;
this.RaisePropertyChanged(() => this.Items);
}
}
....
}
问题是 MvxRecyclerView 不显示任何数据。但它确实如此,当我在 axml 中定义 ItemTemplateId 和 Binding 时(例如 local:MvxItemTemplate="...", local:MvxBind="ItemsSource Items")。
我的目标不是在 axml 中定义它。我想利用在代码中使用这些属性的优势(例如重命名或重构问题)。
是否可以在代码中定义这些绑定(bind)?
最佳答案
在 xml 中设置 MvxItemTemplate 并在 fragment 中创建项目绑定(bind)。
关于android - 如何通过代码绑定(bind)到 MvxRecyclerView ItemsSource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37603630/
我正在使用 MvxRecyclerView,我想为列表中的选定项目设置动画。如何获得对所选项目 View 的引用?我应该使用 TouchDelegate 吗? 最佳答案 您应该能够通过 Recycle
我正在使用 Xamarin 和 MvvmCross 构建一个不错的 Android 应用程序。我正在尝试让 MvxRecyclerView 正常工作,但我做不对。该应用运行但未在 RecycleVie
我在 fragment 中使用了 MvxRecyclerView: 这是 fragment 代码: [MvxFragment(typeof(MainViewModel), Resource.
我无法使用 Fluent API 将 MvxRecyclerView(或其适配器)中的 ItemClick 绑定(bind)到我的 ViewModel 上的命令。如果我将 ItemsSource 和
我想实现 MvxRecyclerView,但在运行时在 SetContentView() 中出现以下异常: System.NotSupportedException: Could not activa
我是一名优秀的程序员,十分优秀!