How to create a list of unselectable Items?

I have a ListBox binded to some data and with an ItemTemplate.
I'd like a list of unselectable items in the list. I cannot find the switch that make the items unselectable.

Can I tell the ListBox or its item to not be selectable or should I use a different control in stead of a ListBox

Any help is greatly appreciated.

<DataTemplate x:Key="myTemplate">

<StackPanel>

<TextBlock Width="265" Text="{Binding Mode=Default, Path=ShortDescription}" Foreground="White" FontSize="10" FontWeight="Bold" TextWrapping="Wrap" />

<TextBlock Width="265" Text="{Binding Mode=Default, Path=LongDescription}" Foreground="White" FontSize="9" TextWrapping="Wrap" />

</StackPanel>

</DataTemplate>

<ListBox Margin="8,117,8,8" x:Name="myList" IsSynchronizedWithCurrentItem="True" ItemTemplate="{StaticResource myTemplate}" Background="Transparent" />



Answer this question

How to create a list of unselectable Items?

  • LuisGarcia

    Works!

    Just setting myListView.SelectedItem = null during the loaded event.

    Thank you so much Chad!


  • Asim_DIT

    Hi AndrewNa,

    I'm not sure I completely understand what you are attempting. However, from my initial understanding, it seems like one of the following would be appropriate:

    If this answers your question, please select "Mark as Answer", if not, could you please describe in further detail what you are attempting to accomplish

    Thank you,

    Chad Campbell



  • a.d.m

    Hi AndreaNa,

    I believe in order to accomplish this, you will need to use the Loaded event (http://msdn2.microsoft.com/en-us/library/system.windows.frameworkelement.loaded.aspx) and in the code behind, write some code to check to see if the first item isFocusable, if it's not, set the selected item to another item.

    Please select "Mark as Answer" if this has answered your question. If not, please let me know how I can help.

    Chad Campbell



  • .NetProgrammer

    Thank you Chad,

    IsFocusable works, at least the item are not selectable. However the first Item in the list is selected by default.

    Any idea how to avoid the selection of the first item

    To apply the IsFocusable I added a Style to the ListBox:

    <Style x:Key="mItemContainerStyle" TargetType="{x:Type ListBoxItem}">

    <Setter Property="Focusable" Value="False" />

    <Setter Property="IsSelected" Value="False" />

    </Style>

    <ListBox ItemContainerStyle="{StaticResource mItemContainerStyle}" ...


  • How to create a list of unselectable Items?