WPF Filter a ListBox

CollectionViewSource class can help here. As far as I can tell it has many capabilities to filter, sort and group collections. ICollectionView view = CollectionViewSource.GetDefaultView(ElementList); view.Filter = (o) => {return o;}//here is the lambda with your conditions to filter When you don’t need any filter just set view.Filter to null. Also check out this article … Read more

Accessing the ScrollViewer of a ListBox from C#

you can try this little helper function usage var scrollViewer = GetDescendantByType(yourListBox, typeof(ScrollViewer)) as ScrollViewer; helper function public static Visual GetDescendantByType(Visual element, Type type) { if (element == null) { return null; } if (element.GetType() == type) { return element; } Visual foundElement = null; if (element is FrameworkElement) { (element as FrameworkElement).ApplyTemplate(); } for … Read more

How can I sort a ListBox using only XAML and no code-behind?

Use a CollectionViewSource: <CollectionViewSource x:Key=”SortedItems” Source=”{Binding CollectionOfStrings}” xmlns:scm=”clr-namespace:System.ComponentModel;assembly=Win‌​dowsBase”> <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName=”SomePropertyOnYourItems”/> </CollectionViewSource.SortDescriptions> </CollectionViewSource> <ListBox ItemsSource=”{Binding Source={StaticResource SortedItems}}”/> You might want to wrap your strings in a custom VM class so you can more easily apply sorting behavior.

WPF: Remove dotted border around focused item in styled listbox

You need to set FocusVisualStyle of each ListBoxItem to null. Steps are bellow 1) Create ItemContainerStyle for the ListBox <Style x:Key=”ListBoxItemStyle1″ TargetType=”{x:Type ListBoxItem}”> <Setter Property=”FocusVisualStyle” Value=”{x:Null}”/> …. 2) Set that style to Listbox <ListBox ItemContainerStyle=”{DynamicResource ListBoxItemStyle1}”

C# : changing listbox row color?

I find solution that instead of using ListBox I used ListView.It allows to change list items BackColor. private void listView1_Refresh() { for (int i = 0; i < listView1.Items.Count; i++) { listView1.Items[i].BackColor = Color.Red; for (int j = 0; j < existingStudents.Count; j++) { if (listView1.Items[i].ToString().Contains(existingStudents[j])) { listView1.Items[i].BackColor = Color.Green; } } } }