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

  • SEARCH
  • Home
  • 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 270933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:04:52+00:00 2026-05-12T00:04:52+00:00

I have a ListBox with ListBoxItem s that contains a nested ListBox . Now

  • 0

I have a ListBox with ListBoxItems that contains a nested ListBox. Now I want the top-level ListBox‘s items to not have a blue background then they are selected (see pic).

Example Image http://img43.imageshack.us/img43/237/window1.png

I tried to use the XAML below with a style to change the background color to transparent as descibed in this blog post. This works, but it also changes the selected background color of the items in the nested ListBox. How do I change it to only apply to the top-level items?

<Window x:Class="WpfTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="350" Width="352">
    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="SampleItemTemplate">
                <Border Margin="5" Background="Gray" CornerRadius="3">
                    <Border.BitmapEffect>
                        <DropShadowBitmapEffect/>
                    </Border.BitmapEffect>
                    <StackPanel Margin="2">
                        <TextBlock Text="{Binding Path=Lid, StringFormat='ProvID: {0}'}"/>
                        <ListBox ItemsSource="{Binding Path=TestOrders}"/>
                    </StackPanel>
                </Border>
            </DataTemplate>
        </Grid.Resources>
        <Button Height="23" Name="button1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" Margin="0,0,12,12" Click="button1_Click">Button</Button>
        <ListBox Name="listBox1" Margin="12,12,12,41" ItemsSource="{Binding}" ItemTemplate="{StaticResource SampleItemTemplate}">
            <ListBox.Resources>
            <Style TargetType="{x:Type ListBoxItem}">
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                </Style.Resources>
            </Style>
            </ListBox.Resources>
        </ListBox>
    </Grid>
</Window>

I understand that this style applies to all objects of type ListBoxItem, but how do I get it to apply only to items in listbox1?

<Style TargetType="{x:Type ListBoxItem}">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
    </Style.Resources>
</Style>

Probably there is a better way to accomplish what I want, in that case, please tell me!

  • 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-05-12T00:04:53+00:00Added an answer on May 12, 2026 at 12:04 am

    Do you need both the “inner” and “outer” items to be selectable? I would probably stick with ItemsControl for the outer list and just let the inner items be selectable. Then you could style ListBoxItem without affecting the “outer” items.

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

Sidebar

Related Questions

I have a ListBox with some ListBoxItems. Each ListBoxItem contains some text and a
I have a listbox item template that contains visual states. I have DisplayStateBehaviors that
I have a ListBox with items that fill TextBox es. How do I identify
I have a UserControl that contains a ListBox that is bound to a CollectionViewSource
Scenario: I have a ListBox and the ListBoxItems have a DataTemplate. What I want
Basically, I have a listbox which contains a set of listboxitem (stacked horizontally). On
I have a listbox of checkboxes that I want to iterate through and check
I have a list box that contains items that are represented by a single
I have a ListBox, that's bound to an ObservableCollection . Each ListBoxItem is displayed
I have a ListBox that has a style defined for ListBoxItems. Inside this style,

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.