CollectionViewSource.GetDefaultView不在Silverlight 3!有什么解决方法? [英] CollectionViewSource.GetDefaultView is not in Silverlight 3! What's the work-around?

查看:164
本文介绍了CollectionViewSource.GetDefaultView不在Silverlight 3!有什么解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Silverlight 3中的 CollectionViewSource.GetDefaultView()方法不是 。在WPF中,我有这个扩展方法:



public static void SetActiveViewModel< ViewModelType>(这个ViewModelBase viewModel,
ViewModelType collectionItem,
ObservableCollection< ViewModelType>集合)其中ViewModelType: ViewModelBase
{
Debug.Assert(collection.Contains(collectionItem));
ICollectionView collectionView = CollectionViewSource.GetDefaultView(collection);
if(collectionView!= null)collectionView.MoveCurrentTo(collectionItem);
}

如何用Silverlight 3编写?

解决方案

Silverlight不包含默认视图的概念。当你要求一个控件在Silverlight绑定到一个集合,它确实绑定到集合,它不绑定到默认视图。



结果我不认为可以有一个直接和完整的端口你的扩展方法。将需要对您的MVVM实现进行一些重新设计。我没有遇到视图模型实例集合的概念,所以我不能确定什么是适当的你的情况。



一些方法我看到 CollectionViewSource 是要么在Xaml中定义 CollectionViewSource 并绑定其<$​​ c $ c > Source 到ViewModel中的内容。或者有一个ViewModel公开一个 CollectionViewSource 属性,并使View xaml绑定到它的 View proeprty。


The CollectionViewSource.GetDefaultView() method is not in Silverlight 3. In WPF I have this extension method:

public static void SetActiveViewModel<ViewModelType>(this ViewModelBase viewModel,
    ViewModelType collectionItem,
    ObservableCollection<ViewModelType> collection) where ViewModelType : ViewModelBase
{
    Debug.Assert(collection.Contains(collectionItem));
    ICollectionView collectionView = CollectionViewSource.GetDefaultView(collection);
    if(collectionView != null) collectionView.MoveCurrentTo(collectionItem);
}

How can this be written in Silverlight 3?

解决方案

Silverlight does not contain the concept of a Default view. When you ask a control in Silverlight to bind to a collection it really does bind to the collection, it does not bind to a default view.

As result I don't think there can be a direct and complete port of your extension method. Some re-engineering of your MVVM implementation will be needed. I've not come across the concept of a collection of view model instances before so I'm not exactly sure what would be appropriate in your case.

A couple of approaches I've seen with CollectionViewSource is to either have the CollectionViewSource defined in the Xaml and bind its Source to something in the ViewModel. Alternatively have a ViewModel expose a CollectionViewSource property and have the View xaml bind to its View proeprty.

这篇关于CollectionViewSource.GetDefaultView不在Silverlight 3!有什么解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆