collectionviewsource

“Object reference not set to an instance of an object” in PresentationFramework with Live Shaping

纵然是瞬间 提交于 2019-12-01 05:43:29
I'm getting a null reference in the PresentationFramework on my LifeShaping filtering: The stack trace isn't giving me much clue: at System.Windows.Data.ListCollectionView.RestoreLiveShaping() at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,

How to handle a CompositeCollection with CollectionView features?

核能气质少年 提交于 2019-12-01 05:18:14
Is there a way to get notified when CompositeCollection's current location changes? I need to have the CompositeCollection monitored by a CollectionView, any ideas are welcommed. You can detect when the current item has changed by monitoring the ICollectionView.CurrentChanged event of your CollectionView. The following code works for me: CompositeCollection cc = new CompositeCollection(); cc.Add(new CollectionContainer { Collection = new string[] { "Oh No!", "Fie" } }); cc.Add(new CollectionContainer { Collection = new string[] { "Zounds", "Ods Bodikins" } }); CollectionViewSource cvs = new

“Object reference not set to an instance of an object” in PresentationFramework with Live Shaping

浪子不回头ぞ 提交于 2019-12-01 03:54:13
问题 I'm getting a null reference in the PresentationFramework on my LifeShaping filtering: The stack trace isn't giving me much clue: at System.Windows.Data.ListCollectionView.RestoreLiveShaping() at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation

How to preserve TwoWay binding of CurrentItem when databinding to CollectionViewSource in ComboBox

♀尐吖头ヾ 提交于 2019-11-30 01:11:47
问题 Lets say we got a simple VM class public class PersonViewModel : Observable { private Person m_Person= new Person("Mike", "Smith"); private readonly ObservableCollection<Person> m_AvailablePersons = new ObservableCollection<Person>( new List<Person> { new Person("Mike", "Smith"), new Person("Jake", "Jackson"), }); public ObservableCollection<Person> AvailablePersons { get { return m_AvailablePersons; } } public Person CurrentPerson { get { return m_Person; } set { m_Person = value;

SelectedItem set to first item with CollectionViewSource

自古美人都是妖i 提交于 2019-11-29 07:10:31
I have a view databound through mvvm light to a viewmodel in my WP7 project. The view contains a Listbox with following settings: <ListBox x:Name="StationList" ItemsSource="{Binding StationList}" SelectedItem="{Binding SelectedStation, Mode=TwoWay}" > The StationList is a ObservableCollection. Now when the view gets loaded, everything looks great! The list is shown and NO item is selected! But when I change the XAML to: <ListBox x:Name="StationList" ItemsSource="{Binding Source={StaticResource StationListSorted}}" SelectedItem="{Binding SelectedStation, Mode=TwoWay}" > With the

Binding a CollectionViewSource within a DataTemplate

风流意气都作罢 提交于 2019-11-29 01:46:20
'ContentTemplate' is a DataTemplate that displays an object which has a member 'FooList' (an ObservableCollection). <DataTemplate x:Key="ContentTemplate"> <ListBox ItemsSource="{Binding Path=FOO}"> ... </ListBox> </DataTemplate> I need to be able to filter that FooList using a CollectionViewSource. This is usually been straight forward but I can't seem to get the binding to work within a DataTemplate. I attempted to this: <DataTemplate x:Key="ContentTemplate"> <DataTemplate.Resources> <CollectionViewSource x:Key="CVS" Source="{Binding Path=FooList}" Filter="FooFilter"/> <DataTemplate.Resources

Re-sort WPF DataGrid after bounded Data has changed

ⅰ亾dé卋堺 提交于 2019-11-28 20:17:57
I am looking for a way to re-sort my DataGrid when the underlying data has changed . (The setting is quite standard: The DataGrid's ItemSource property is bound to an ObservableCollection ; The columns are DataGridTextColumns ; The data inside the DataGrid reacts correctly on changes inside the ObservableCollection; Sorting works fine when clicked with the mouse) Any ideas ? marc wellman It took me the whole afternoon but I finally found a solution that is surprisingly simple , short and efficient : To control the behaviors of the UI control in question (here a DataGrid ) one might simply use

WPF CollectionViewSource Multiple Views?

徘徊边缘 提交于 2019-11-28 08:20:51
I've written a Custom WPF Control with search extension, let's name it MyControl . The Control is a descendent of an ItemsControl class. So I feed the the data source to it like this: The control itself uses protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue) { if (newValue != null) { ICollectionView view = CollectionViewSource.GetDefaultView(newValue); view.Filter += this.FilterPredicate; } if (oldValue != null) { ICollectionView view = CollectionViewSource.GetDefaultView(oldValue); view.Filter -= this.FilterPredicate;

CollectionViewSource with custom sort

家住魔仙堡 提交于 2019-11-28 03:27:03
问题 I'm new to WPF and I'm having difficulty trying to sort a CollectionViewSource with a custom sort. Here's the situation: I have a SearchView that is called with a parameter which becomes it's datacontext like so: mainView.SetGlobalOverlay(New SearchView With {.DataContext = interventionViewModel}) In the SearchView.xaml, I then bind the CollectionViewSource to the collection : <CollectionViewSource x:Key="UnitsCollection" Filter="UnitsCollection_Filter" Source="{Binding Path=Units}" /> Now, I

Trigger Filter on CollectionViewSource

自古美人都是妖i 提交于 2019-11-28 03:08:36
I am working on a WPF desktop application using the MVVM pattern. I am trying to filter some items out of a ListView based on the text typed in a TextBox . I want the ListView items to be filtered as I change the text. I want to know how to trigger the filter when the filter text changes. The ListView binds to a CollectionViewSource , which binds to the ObservableCollection on my ViewModel. The TextBox for the filter text binds to a string on the ViewModel, with UpdateSourceTrigger=PropertyChanged , as it should be. <CollectionViewSource x:Key="ProjectsCollection" Source="{Binding Path