- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只是想知道Mvvmmcross框架中是否潜藏着ExpandableListViews或与之相似的功能,还是这种控件不适用于多平台要求。
的功能在
http://deapsquatter.blogspot.com/2013/02/mvvmcrossdeapextensions.html很酷,但是不确定扩展/折叠功能是否可用。
任何指针/示例代码将不胜感激
最佳答案
就是这样(我将其放入Deepsqautter的代码中)。整理代码后,我会将其放在方便的位置,或者它可能是mvvmcross本身的有用补充...
风景:
public class BindableExpandableListView : ExpandableListView
{
public BindableExpandableListView(Context context, IAttributeSet attrs)
: this(context, attrs, new BindableExpandableListAdapter(context))
{
}
public BindableExpandableListView(Context context, IAttributeSet attrs, BindableExpandableListAdapter adapter)
: base(context, attrs)
{
var groupTemplateId = MvxAttributeHelpers.ReadAttributeValue(context, attrs,
MvxAndroidBindingResource.Instance
.ListViewStylableGroupId,
AndroidBindingResource.Instance
.BindableListGroupItemTemplateId);
var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
SetAdapter(adapter);
adapter.GroupTemplateId = groupTemplateId;
adapter.ItemTemplateId = itemTemplateId;
}
// An expandableListView has ExpandableListAdapter as propertyname, but Adapter still exists but is always null.
protected BindableExpandableListAdapter ThisAdapter { get { return ExpandableListAdapter as BindableExpandableListAdapter; } }
private IEnumerable _itemsSource;
[MvxSetToNullAfterBinding]
public virtual IEnumerable ItemsSource
{
get { return ThisAdapter.ItemsSource; }
set { ThisAdapter.ItemsSource = value; }
}
public int ItemTemplateId
{
get { return ThisAdapter.ItemTemplateId; }
set { ThisAdapter.ItemTemplateId = value; }
}
private ICommand _itemClick;
public new ICommand ItemClick
{
get { return _itemClick; }
set { _itemClick = value; if (_itemClick != null) EnsureItemClickOverloaded(); }
}
public ICommand GroupClick { get; set; }
private bool _itemClickOverloaded = false;
private void EnsureItemClickOverloaded()
{
if (_itemClickOverloaded)
return;
_itemClickOverloaded = true;
base.ChildClick += (sender, args) => ExecuteCommandOnItem(this.ItemClick, args.GroupPosition, args.ChildPosition);
}
protected virtual void ExecuteCommandOnItem(ICommand command, int groupPosition, int position)
{
if (command == null)
return;
var item = ThisAdapter.GetRawItem(groupPosition, position);
if (item == null)
return;
if (!command.CanExecute(item))
return;
command.Execute(item);
}
}
和适配器
public class BindableExpandableListAdapter : MvxAdapter, IExpandableListAdapter
{
private IList _itemsSource;
public BindableExpandableListAdapter(Context context)
: base(context)
{
}
int groupTemplateId;
public int GroupTemplateId
{
get { return groupTemplateId; }
set
{
if (groupTemplateId == value)
return;
groupTemplateId = value;
// since the template has changed then let's force the list to redisplay by firing NotifyDataSetChanged()
if (ItemsSource != null)
NotifyDataSetChanged();
}
}
protected override void SetItemsSource(System.Collections.IEnumerable value)
{
Mvx.Trace("Setting itemssource");
if (_itemsSource == value)
return;
var existingObservable = _itemsSource as INotifyCollectionChanged;
if (existingObservable != null)
existingObservable.CollectionChanged -= OnItemsSourceCollectionChanged;
_itemsSource = value as IList;
var newObservable = _itemsSource as INotifyCollectionChanged;
if (newObservable != null)
newObservable.CollectionChanged += OnItemsSourceCollectionChanged;
if (value != null)
{
// dit weggehaald FlattenAndSetSource(value);
}
else
base.SetItemsSource(null);
}
public int GroupCount { get { return (_itemsSource != null ? _itemsSource.Count : 0); } }
public void OnGroupExpanded(int groupPosition)
{
// do nothing
}
public void OnGroupCollapsed(int groupPosition)
{
// do nothing
}
public bool IsChildSelectable(int groupPosition, int childPosition)
{
return true;
}
public View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
var item = _itemsSource[groupPosition];
return base.GetBindableView(convertView, item, GroupTemplateId);
}
public long GetGroupId(int groupPosition)
{
return groupPosition;
}
public Java.Lang.Object GetGroup(int groupPosition)
{
return null;
}
public long GetCombinedGroupId(long groupId)
{
return groupId;
}
public long GetCombinedChildId(long groupId, long childId)
{
return childId;
}
public object GetRawItem(int groupPosition, int position)
{
return ((_itemsSource[groupPosition]) as IEnumerable).Cast<object>().ToList()[position];
}
public View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
var sublist = ((_itemsSource[groupPosition]) as IEnumerable).Cast<object>().ToList();
var item = sublist[childPosition];
return base.GetBindableView(convertView, item, ItemTemplateId);
}
public int GetChildrenCount(int groupPosition)
{
return ((_itemsSource[groupPosition]) as IEnumerable).Cast<object>().ToList().Count();
}
public long GetChildId(int groupPosition, int childPosition)
{
return childPosition;
}
public Java.Lang.Object GetChild(int groupPosition, int childPosition)
{
return null;
}
//public object GetRawItem
}
以及示例XAML代码:
<DeapExtensions.Binding.Droid.Views.BindableExpandableListView
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/toclist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource Chapters; ItemClick ShowCommand"
local:MvxItemTemplate="@layout/indextocsectionlistitem"
local:GroupItemTemplate="@layout/indextocitem"
android:background="@android:color/white" />
然后是一些数据示例(伪代码):
public class SubItem {
public String Name {get; set;}
}
// this is the special part: a chapter does not CONTAIN a sublist, but IS a list of subitems.
public class Chapter : List<Subitem> {
public String Name {get; set;}
}
// en some usage code
var chapters = new List<Chapter>();
var chapter = new Chapter(){Name = "chap 1"};
chapter.Add(new SubItem(){Name = " 1"});
chapter.Add(new SubItem(){Name = "item 2"});
chapters.Add(chap);
这是我的MvxBindingAttributes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MvxBinding">
<attr name="MvxBind" format="string"/>
<attr name="MvxLang" format="string"/>
</declare-styleable>
<declare-styleable name="MvxControl">
<attr name="MvxTemplate" format="string"/>
</declare-styleable>
<declare-styleable name="MvxListView">
<attr name="MvxItemTemplate" format="string"/>
<attr name="MvxDropDownItemTemplate" format="string"/>
<attr name="GroupItemTemplate" format="string"/>
</declare-styleable>
<item type="id" name="MvxBindingTagUnique"/>
<declare-styleable name="MvxImageView">
<attr name="MvxSource" format="string"/>
</declare-styleable>
</resources>
顺便说一句:我在MvvmCross中只剩下一个项目,其余的已经转换为Xamarin.Forms甚至是Xamarin。因此代码不再更新。
关于expandablelistview - mvvmcross expandablelistview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15010246/
我在MvvmCross应用程序中使用了Messenger插件,并且注意到它有时会清除我的订阅(“一个或多个监听器失败-已清除清除”)。这在我的应用程序中导致错误。默认情况下,我对订阅使用弱引用,并且我
我正在开发 MVVMCross v3,我想创建自己的插件,我遵循了本教程(适用于 vNext) http://slodge.blogspot.fr/2012/10/build-new-plugin-f
我在 View 模型中有一些来自 Init 的异步调用。问题是有时异步调用在 OnCreate 之前返回,并且 UI 中的属性没有更新。 当我们必须初始化异步数据时,是否有适合这种情况的异步/等待模型
我正在尝试在我的应用程序之一中使用 MvvmCross v3,该应用程序由事件、内容提供者和广播接收器组成。但是,我并没有完全成功。 该应用程序由一个包含逻辑、模型和 View 模型的核心 PCL 和
我希望能够在调试 MvvmCross 应用程序时单步执行 MvvmCross 源代码。而且我想保持使 MvvmCross 库保持最新的过程简单。目前,如果不编辑大量 .csproj 文件(由于某些 P
我有一个 WPF MVVM 应用程序,我想重构它以使用 MvvmCross 来支持 Android 实现的 WPF 和 Mono。 我们的应用程序的 View 包括: 始终可见的工具栏 导航栏区域 主
标题说明了一切。根据您的经验,这两个框架之间的主要区别是什么? 我们什么时候应该使用一个而不是另一个? 预期用途:跨平台开发(Windows 8、iOS、Android、WindowsRT、Mac)。
我希望用户能够将有关我的应用的反馈发送到某个地址。使用电子邮件插件,这一切都很好,但在电子邮件正文中,我想预先填充有关他们正在运行的应用程序的一些信息。 理想情况下,我想要设备、操作系统、屏幕分辨率、
我正在使用 mvvmcross 开发一个 iOS 项目。 应用程序导航是这样的:首先它从初始屏幕 (1) 开始,然后导航到 (2),一个在 3 个选项之间进行选择的 View ,在 View (3)
我正在尝试使用 Visual Studio Team Services(以前是 Visual Studio Online) 和 VSTS Build Agent< 在 Mac 上构建 Xamarin.
我在 View 模型中有一个枚举属性,如果属性值是特定值,我想使标签可见 States state; public States State { get { return this.state
我正在创建类似于 N=32 - The Truth about ViewModels... starring MvxView on the iPad - N+1 days of MvvmCross 中
在MvvmCross应用程序中,我有一个页面具有经典的聊天行为(类似于WhatsApp):此页面显示了两个用户之间交换的消息的历史记录,最后一条消息位于列表的底部。 我已经在Windows Phone
我正在尝试在基于 Xamarin Android 的布局中创建一个自动完成控件。我正在使用 MVVMCross。 我在片段中创建了以下 AXML 布局。 我更新了我的 View
将 Fody 与 MvvmCross 集成的正确方法是什么?我是否需要任何特殊的管道代码或配置来确保调用 MvxNotifyPropertyChanged 类中正确的 RaisePropertyCha
我要同时为我的应用程序实现两种类型的导航,侧边栏导航和父子导航。 我的应用程序从汉堡(侧边栏)菜单开始。 侧边栏菜单中的第一项应执行导航堆栈的重置并打开主视图。 主视图 Controller 应该启动
这个问答中回答的问题是我们如何使用 mvvmcross 在我们的 UI 项目上显示颜色,当我们有一个带有枚举属性的 ViewModel 时,不需要有 Color 属性,也没有 ValueConvert
将参数从一个 View 模型传递到另一个 View 模型,然后修改它然后将其返回到原始 View 模型的推荐方法是什么? 关于将值传递给 View ,即 ShowViewModel(new{ para
I have one custom object in my ViewModel.I want to bind only one of its member to textview in my dro
我想使用 Mvvmcross 为多个平台制作应用程序。 我对 Mvvmcross 等 PCL 库使用配置文件 104,但此配置文件的目标是 .NET 4.5。我想以 .NET 4.0 为目标,以便在
我是一名优秀的程序员,十分优秀!