collectionviewsource

Proper way to use CollectionViewSource in ViewModel

不羁的心 提交于 2019-11-27 17:59:04
I used Drag and Drop to bind Data Source object (a DB model) to DataGrid (basically following this example in Entity Framework Databinding with WPF . Everything works fine with this implementation. XAML <Window.Resources> <CollectionViewSource x:Key="categoryViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Category}, CreateList=True}"/> </Window.Resources> <Grid DataContext="{StaticResource categoryViewSource}"> .. Code Behind private void Window_Loaded(object sender, RoutedEventArgs e) { System.Windows.Data.CollectionViewSource categoryViewSource = ((System.Windows.Data

Binding a CollectionViewSource within a DataTemplate

不问归期 提交于 2019-11-27 16:12:06
问题 '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>

Re-sort WPF DataGrid after bounded Data has changed

家住魔仙堡 提交于 2019-11-27 12:50:04
问题 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 ? 回答1: It took me the whole afternoon but I finally found a solution that is surprisingly simple , short and efficient :

WPF DataGrid CustomSort for each Column

有些话、适合烂在心里 提交于 2019-11-27 06:46:19
I have a WPF DataGrid bound to a CollectionViewSource that encapsulates an ObservableCollection. This CollectionViewSource has two main objectives: 1) To group each item by a specific property of T. I'm using a ValueConverter in the GroupDescription to get the grouping behaviour I want. 2) To sort the grid by a) primarily the group name (as defined above) and b) the individual group items. I'm achieving this by attaching a custom IComparer to the CollectionViewSource's 'CustomSort' property. This works great for the most part, however as soon as a column header is clicked, the sorting logic is

Trigger Filter on CollectionViewSource

纵饮孤独 提交于 2019-11-27 05:04:11
问题 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

In WPF can you filter a CollectionViewSource without code behind?

ぃ、小莉子 提交于 2019-11-26 22:13:24
问题 Really the subject says it all. <CollectionViewSource x:Key="MyData" Source="{Binding}" Filter="{ SomethingMagicInXaml? }" /> It's not that I can't have code behind. It just nags at me. 回答1: You can do pretty much anything in XAML if you "try hard enough", up to writing whole programs in it. You will never get around code behind (well, if you use libraries you don't have to write any but the application still relies on it of course), here's an example of what you can do in this specific case:

In WPF can you filter a CollectionViewSource without code behind?

我只是一个虾纸丫 提交于 2019-11-26 20:47:40
Really the subject says it all. <CollectionViewSource x:Key="MyData" Source="{Binding}" Filter="{ SomethingMagicInXaml? }" /> It's not that I can't have code behind. It just nags at me. You can do pretty much anything in XAML if you "try hard enough", up to writing whole programs in it . You will never get around code behind (well, if you use libraries you don't have to write any but the application still relies on it of course), here's an example of what you can do in this specific case: <CollectionViewSource x:Key="Filtered" Source="{Binding DpData}" xmlns:me="clr-namespace:Test

Proper way to use CollectionViewSource in ViewModel

大憨熊 提交于 2019-11-26 15:34:40
问题 I used Drag and Drop to bind Data Source object (a DB model) to DataGrid (basically following this example in Entity Framework Databinding with WPF. Everything works fine with this implementation. XAML <Window.Resources> <CollectionViewSource x:Key="categoryViewSource" d:DesignSource="{d:DesignInstance {x:Type local:Category}, CreateList=True}"/> </Window.Resources> <Grid DataContext="{StaticResource categoryViewSource}"> .. Code Behind private void Window_Loaded(object sender,

WPF DataGrid CustomSort for each Column

末鹿安然 提交于 2019-11-26 12:56:08
问题 I have a WPF DataGrid bound to a CollectionViewSource that encapsulates an ObservableCollection. This CollectionViewSource has two main objectives: 1) To group each item by a specific property of T. I\'m using a ValueConverter in the GroupDescription to get the grouping behaviour I want. 2) To sort the grid by a) primarily the group name (as defined above) and b) the individual group items. I\'m achieving this by attaching a custom IComparer to the CollectionViewSource\'s \'CustomSort\'

Grouping items in a ComboBox

安稳与你 提交于 2019-11-26 09:33:17
问题 I have a ListView that contains two types of objects, single and multiple. The single is a ordinary TextBlock while the multiple is a ComboBox with items. I\'m trying to group the items in the ComboBox without success. Is it possible? Or should I go for a different approach? What I\'m trying to achieve: [ComboBox v] [Header ] [ Item] [ Item] [Header ] [ Item] 回答1: It is possible. Use a ListCollectionView with a GroupDescription as the ItemsSource and just provide a GroupStyle to your ComboBox