Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8595095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:21:18+00:00 2026-06-12T00:21:18+00:00

We’re trying to create a ListBox which has a few items inside that the

  • 0

We’re trying to create a ListBox which has a few items inside that the user cannot select. Think the group headings in a grouped listbox, except these are independent items (i.e. no indented children.) We just want to display a message in the list.

Here’s a mock-up of what we currently display if there are ‘Foo’ items…

Foo 1
Foo 2
Foo 3
--------------   <-- This is of type 'Separator' so it's styled as not-selectable by default.
Add new Foo...
Manage Foos...

…and if there aren’t any Foo items, we display this…

[No Foo Items]   <-- This one should not be selectable, the same as a separator
--------------   <-- This is of type 'Separator' so it's styled as not-selectable by default.
Add new Foo...
Manage Foos...

Now again, we already have the code that properly handles what’s displayed (see below). We’re wondering what’s the proper way to disable that entry from being able to be selected.

What we don’t know is how to style that ListBoxItem so the selection skips right over it, nor can the user click on it.

Code

Someone asked me to see my code, so here it is. Not really relevant to the question, but should show people how I did this.

Note: We template the string.Empty in the XAML to show the localized ‘No xxx Items’ message. string.Empty is just a placeholder that we can target.

Note 2: FauxData is a simple library of items and collections used for testing so I don’t have to constantly create them from scratch. SimpleItemCollection for instance creates ten SimpleItem objects in the constructor, pre-populated with things like Name, Description, IsSelected, etc. all fully supporting INotifyPropertyChanged and collection change notifications. I have the same thing with HierarchicalItemsCollection which adds Parent, Children and IsExpanded, etc. It saves a LOT of work when testing code and controls!

Finally, this is from a simple test, or ‘playground’ app. As such, it’s not supposed to represent the best way to do things, just to show a concept. Yes, it can be cleaned up a lot, but you get the general idea.

Anyway, on to the code…

using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using FauxData;

namespace Playground.ListTest
{
    [LaunchEntry("List Test")]
    public partial class Main : Window
    {
        SimpleItemCollection itemsCollection = new SimpleItemCollection(); // Default constructor creates 10 items

        public Main()
        {
            InitializeComponent();
            MainListBox.ItemsSource = CreateCompositeCollection();
        }

        private CompositeCollection CreateCompositeCollection()
        {
            var EmptyHolder = new ObservableCollection<object>();

            itemsCollection.CollectionChanged += (s,e) => {

                if(itemsCollection.Count != 0)
                    EmptyHolder.Clear();
                else if(EmptyHolder.Count == 0)
                    EmptyHolder.Add(string.Empty);

            };

            var cc = new CompositeCollection();

            cc.Add(new CollectionContainer(){ Collection = itemsCollection });
            cc.Add(new CollectionContainer(){ Collection = EmptyHolder });
            cc.Add(new Separator());
            cc.Add(ApplicationCommands.New);   // <-- Pops a dialog to enter a new item
            cc.Add(ApplicationCommands.Open);  // <-- Shows an item management window

            return cc;

        }

        private void Test_Click(object sender, RoutedEventArgs e)
        {
            if(itemsCollection.Count != 0)
                itemsCollection.Clear();
            else
                itemsCollection.Add(new SimpleItem(){Name = "New item" });
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:21:19+00:00Added an answer on June 12, 2026 at 12:21 am

    As Focusable="false" does not cover all options (e.g. click and drag select) i would recommend setting IsEnabled to false instead.

    (The greyed out text is a matter of the ListBoxItem style/template, so if you do not like it you will need to override it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an array which has BIG numbers and small numbers in it. I
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.