Tag: collectionviewsource

如何使用CollectionViewSource对LongListSelector进行排序

我有一个LongListSelector ,当前正在填充来自IsolatedStorage图像。 我希望能够按日期按升序或降序对这些进行排序。 我一直在参考http://babaandthepigman.wordpress.com/2011/07/03/wp7-collectionviewsource-sorting-a-listbox/寻求帮助。 出于某种原因,我无法将LongListSelector的ItemsSource绑定到CollectionViewSource以实现排序function。 PictureRepository.cs(在应用程序启动时从IsolatedStorage加载图片) #region Constants public const string IsolatedStoragePath = “Pictures”; #endregion #region Properties public ObservableCollection Pictures { get; private set; } #endregion #region Singleton Pattern private PictureRepository() { LoadAllPicturesFromIsolatedStorage(); } public static readonly PictureRepository Instance = new PictureRepository(); #endregion /// /// Saves to local storage /// This method gets two parameters: […]

Windows Phone CollectionViewSort没有显示任何内容

我正在尝试在WP8应用程序中开发一个页面,该应用程序顶部有一个搜索框,以及与下面的搜索匹配的项目列表,随着搜索框的更新而更新。 很简单,对吧? 除了我不能让它工作。 在仔细阅读StackOverflow和interwebz之后,推荐的解决方案似乎是使用CollectionViewSource 。 好吧,我正在尝试使用它,没有任何项目出现。 一旦我切换到包含我在XAML中的项目的ObservableCollection ,一切都显示正常。 我的数据是从数据库异步加载的。 XAML 查看模型 public class MyViewModel { private ObservableCollection _allItems = new ObservableCollection(); public CollectionViewSource SearchResults { get; private set; } public MyViewModel() { SearchResults = new CollectionViewSource { Source = _allItems }; _allItems.CollectionChanged += (_, __) => SearchResults.View.Refresh(); LoadAllItemsAsync(); } private async void LoadAllItemsAsync() { IList […]

在Windows Phone 7或Windows Phone 8中使用CollectionView进行LongListSelector分组

我遇到了与下面标签中列出的相同的问题 是否可以将CollectionView与LongListSelector一起使用进行分组? 我使用以下代码将LongListSelector与分组绑定。 CollectionViewSource cv = new CollectionViewSource(); cv.Source = comments; cv.GroupDescriptions.Add(new PropertyGroupDescription(“Filter”)); listSelector.HideEmptyGroups = true; listSelector.ItemsSource = cv.View.Groups; 但它没有显示任何东西。 有人可以帮我这个吗?

我的CollectionViewSource没有获取更改

我有一个ListView,我在后面的代码中绑定到CollectionViewSource: collectionView = CollectionViewSource.GetDefaultView(TableView.ItemsSource); collectionView.SortDescriptions.Clear(); collectionView.SortDescriptions.Add(new SortDescription(propertyName, direction)); TableView是ListView,propertyName是我想要排序的列的名称,direction是升序或降序。 对于ItemSource,XAML具有以下内容: ItemsSource=”{Binding Rows}” 对于Rows,后面的代码有以下内容: List rows; public List Rows { get { return rows; } set { rows = value; UpdateProperty(“Rows”); } } 更新如下: public void Update() { …generate a list of rows… Rows = …rows… } 调用Update时会出现问题,列表视图会更新,但会丢失以前在CollectionViewSource上的排序集。

使用CollectionViewSource绑定

我正在尝试使用CollectionViewSource实现一些combobox排序。 此combobox实际上是数据模板的一部分,并在列表视图中重复。 我的第一种方法似乎有效(使用CollectionViewSource)但我的所有combobox都共享相同的数据上下文。 这使得每当其他一个盒子被改变时,所有其他盒子都改变以反映 – 而不是期望的副作用。 我决定退回并尝试使用内联xaml实现一个基本的combobox(不在数据模板中)来指定CollectionViewSource(而不是将cvs创建为静态资源)。 我无法成功显示数据。 因为我还是WPF的新手,所以我可能会完全错误。 这是我的combobox的xaml: 此combobox所在的用户控件的DataContext绑定到一个对象,该对象具有名为Configurations的ObservableCollection,并且每个配置都有一个名为AgencyName的属性。 我已经证实使用没有cvs的标准绑定可以正常工作,所以我知道在那个协议中一切都很好。 任何帮助都会非常感激,因为我已经找不到我的老板的借口:)。 我也不想下载代码并在后面的代码中进行排序(我可以在构建ObservableCollection时使用,但是违反DRY原则的恕我直言)。

WPF DataGrid过滤 – 刷新CollectionViewSource刷新

我想知道如何在单击按钮时刷新CollectionViewSource? 到目前为止我有 这创建了CollectionViewSource …… <DataGrid HorizontalAlignment="Left" Height="210" Margin="47,153,0,0" VerticalAlignment="Top" Width="410" ItemsSource="{Binding Source={StaticResource cvsCustomers}}" CanUserAddRows="False" 这将源绑定到我的Datagrid private void CollectionViewSource_Filter(object sender, FilterEventArgs e) { Customer t = e.Item as Customer; if (t != null) // If filter is turned on, filter completed items. { if (t.Name.Contains(txtSearch.Text)) { e.Accepted = true; } else { e.Accepted = false; } […]

CollectionViewSource使用问题

我正在尝试基本使用CollectionViewSource,我必须遗漏一些东西,因为它只是不起作用。 这是我的XAML: 这编译很好,但是当我运行应用程序时,我收到此错误: 无法将属性’ItemsSource’中的值转换为类型的对象 ‘System.Collections.IEnumerable’。 ‘System.Windows.Data.CollectionViewSource’ 不是属性’ItemsSource’的有效值。 对象出错 标记文件’WIAssistant’中的’System.Windows.Controls.ListBox’;组件/ main.xaml 这是我附加的集合: // The mappings used to copy the values of the fields of one WorkItem to another. public ObservableCollection WorkItemTypeMappings { get { return (ObservableCollection) GetValue(WorkItemTypeMappingsProperty); } set { SetValue(WorkItemTypeMappingsProperty, value); } } public static readonly DependencyProperty WorkItemTypeMappingsProperty = DependencyProperty.Register(“WorkItemTypeMappings”, typeof(ObservableCollection), typeof(MainMediator), new UIPropertyMetadata(null)); 我只想对对象Project […]

如何从CollectionViewSource获取项目数?

我正在使用CollectionViewSource来过滤ListBox中显示的记录。 xaml如下。 这是我的代码behing(请不要介意这个代码隐藏,在实际的应用程序中,我使用最好的MVVM来实现这个场景)。 public partial class ListBoxFilterUsingCollectionViewSource : Window { private string _text=””; private readonly CollectionViewSource _viewSource; public ListBoxFilterUsingCollectionViewSource() { InitializeComponent(); _viewSource = this.FindResource(“cvs”) as CollectionViewSource; } private void CollectionViewSource_Filter(object sender, FilterEventArgs e) { var character = e.Item as Character; e.Accepted = character != null && character.First.ToLower().Contains(_text.ToLower()); } private void txtSearch_TextChanged(object sender, TextChangedEventArgs e) { […]

在数据绑定到ComboBox中的CollectionViewSource时,如何保留CurrentItem的TwoWay绑定

假设我们有一个简单的VM类 public class PersonViewModel : Observable { private Person m_Person= new Person(“Mike”, “Smith”); private readonly ObservableCollection m_AvailablePersons = new ObservableCollection( new List { new Person(“Mike”, “Smith”), new Person(“Jake”, “Jackson”), }); public ObservableCollection AvailablePersons { get { return m_AvailablePersons; } } public Person CurrentPerson { get { return m_Person; } set { m_Person = value; NotifyPropertyChanged(“CurrentPerson”); […]

在有界数据发生更改后重新排序WPF DataGrid

我正在寻找一种方法来在基础数据发生变化时重新排序我的DataGrid 。 (设置非常标准:DataGrid的ItemSource属性绑定到ObservableCollection ;列是DataGridTextColumns ; DataGridTextColumns的数据对ObservableCollection内部的更改做出正确反应;使用鼠标单击时排序工作正常) 有任何想法吗 ?