Re-sort WPF DataGrid after bounded Data has changed

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 a CollectionViewSource. It acts as a kind of representative for the UI control inside your ViewModel without completely breaking … Read more

Grouping items in a ComboBox

It is possible. Use a ListCollectionView with a GroupDescription as the ItemsSource and just provide a GroupStyle to your ComboBox. See sample below: XAML: <Window x:Class=”StackOverflow.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:local=”clr-namespace:StackOverflow” xmlns:uc=”clr-namespace:StackOverflow.UserControls” Title=”MainWindow” Height=”350″ Width=”525″> <StackPanel> <ComboBox x:Name=”comboBox”> <ComboBox.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <TextBlock Text=”{Binding Name}”/> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ComboBox.GroupStyle> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text=”{Binding Name}”/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> … Read more

WPF Multiple CollectionView with different filters on same collection

This answer helped me with this exact problem. The static CollectionViewSource.GetDefaultView(coll) method will always return the same reference for a given collection, so basing multiple collection views on the same reference will be counterproductive. By instantiating the view as follows: ICollectionView filteredView = new CollectionViewSource { Source=messageList }.View; The view can now be filtered/sorted/grouped independently … Read more

Trigger Filter on CollectionViewSource

Don’t create a CollectionViewSource in your view. Instead, create a property of type ICollectionView in your view model and bind ListView.ItemsSource to it. Once you’ve done this, you can put logic in the FilterText property’s setter that calls Refresh() on the ICollectionView whenever the user changes it. You’ll find that this also simplifies the problem … Read more

Proper way to use CollectionViewSource in ViewModel

You have two options to use CollectionViewSource properly with MVVM – Expose an ObservableCollection of items (Categories in your case) through your ViewModel and create CollectionViewSource in XAML like this – <CollectionViewSource Source=”{Binding Path=Categories}”> <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName=”CategoryName” /> </CollectionViewSource.SortDescriptions> </CollectionViewSource> scm: xmlns:scm=”clr-namespace:System.ComponentModel;assembly=Wind‌​owsBase” see this – Filtering collections from XAML using CollectionViewSource Create and Expose an … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)