Picture of Rahul NathRahul Nath
  • Home
  • Blog
  • About
Skip to main content

Scrolling a Disabled Listbox in WPF

Dotnet·Aug 6, 2009
Skip Ad

Recently I had a requirement when developing an application,where i needed a listbox which was to be disabled but yet can be scrolled,so that all the contents in it was visible.Applying the property,IsEnabled=False makes the whole listbox disabled even disabling the scroll. I just found out a way around this.I created a custom listbox(MyScrollableListbox) with a property IsItemsEnabled.Setting this property to true,gives the normal listbox behaviour.When set to false only the ItemsPresenter of the listbox is disabled,so that scrolling is possible

The Custom Listbox looks like this(just one property added for now)

Public Class MyScrollableListbox
Inherits ListBox
Public Property IsItemsEnabled() As Boolean
Get
Return GetValue(IsItemsEnabledProperty)
End Get
Set(ByVal value As Boolean)
SetValue(IsItemsEnabledProperty, value)
End Set
End Property
Public Shared ReadOnly IsItemsEnabledProperty As DependencyProperty = _
DependencyProperty.Register("IsItemsEnabled", _
GetType(Boolean), GetType(MyScrollableListbox), _
New FrameworkPropertyMetadata(Nothing))
End Class

In the xaml(or if you are going to make it a custom control then you can give it in your Generic.xaml)

Now if you set the property IsItemsEnabled to false the listbox will be disabled,but allowing you to scroll.

edit: Added in CodeProject

Hope it helps :)

Dotnet
Back to Blog

Table of contents

About the author

R

Rahul Nath

Software engineer passionate about AWS, .NET, and building better developer experiences. I write about cloud architecture, productivity, and the lessons learned from over a decade in software development.