There is no ListBox.SelectionMode=”None”, is there another way to disable selection in a listbox?

Approach 1 – ItemsControl Unless you need other aspects of the ListBox, you could use ItemsControl instead. It places items in the ItemsPanel and doesn’t have the concept of selection. <ItemsControl ItemsSource=”{Binding MyItems}” /> By default, ItemsControl doesn’t support virtualization of its child elements. If you have a lot of items, virtualization can reduce memory … Read more

Binding Listbox to List in WinForms

You’re looking for the DataSource property: List<SomeType> someList = …; myListBox.DataSource = someList; You should also set the DisplayMember property to the name of a property in the object that you want the listbox to display. If you don’t, it will call ToString().

Background color of a ListBox item (Windows Forms)

Thanks for the answer by Grad van Horck. It guided me in the correct direction. To support text (not just background color), here is my fully working code: //global brushes with ordinary/selected colors private SolidBrush reportsForegroundBrushSelected = new SolidBrush(Color.White); private SolidBrush reportsForegroundBrush = new SolidBrush(Color.Black); private SolidBrush reportsBackgroundBrushSelected = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight)); private SolidBrush reportsBackgroundBrush1 = … Read more

disable mouse wheel on itemscontrol in wpf

The answer you have referenced is exactly what is causing your problem, the ListBox (which is composed of among other things a ScrollViewer) inside your ScrollViewer catches the MouseWheel event and handles it, preventing it from bubbling and thus the ScrollViewer has no idea the event ever occurred. Use the following extremely simple ControlTemplate for … Read more

Why do I get an OutOfMemoryException when I have images in my ListBox?

Oh, I recently killed whole day to make this working! So the solution is: Make your Image control free resources. So set the BitmapImage bitmapImage = image.Source as BitmapImage; bitmapImage.UriSource = null; image.Source = null; as it was mentioned before. Make sure you virtualize _bitmap on every item of the list. You should load it … Read more

tech