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 6940495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:45:35+00:00 2026-05-27T12:45:35+00:00

I have the code: <ListBox Style={StaticResource DeviceListBox} ItemsSource={Binding MeterList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}} SelectedItem={Binding

  • 0

I have the code:

<ListBox Style="{StaticResource DeviceListBox}"
                 ItemsSource="{Binding MeterList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                 SelectedItem="{Binding CurrentMeter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
                 ItemContainerStyleSelector="{StaticResource DeviceListItemStyleSelector}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Style="{StaticResource DeviceListText}" Text="{Binding Name}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>

I use ItemContainerStyleSelector="{StaticResource DeviceListItemStyleSelector}" to change background color in each listbox items (e.g. black or silver, see – http://msdn.microsoft.com/en-us/library/system.windows.controls.styleselector.aspx). And it works. But if I add ItemContainerStyle="{StaticResource DeviceListItemStyle}" to create some triggers etc in DeviceListItemStyle then DeviceListItemStyleSelector doesn’t work. Help me, please!)

  • 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-27T12:45:36+00:00Added an answer on May 27, 2026 at 12:45 pm

    The ItemContainerStyleSelector selects a Style based on some logic, so obviously setting the Style manually will overwrite whatever Style your Selector applied.

    Why don’t you just set the background color in your ItemContainerStyle?

    <Style x:Key="DeviceListItemStyle" TargetType="{x:Type ListBoxItem}">
        <Setter Property="Background" Value="Black" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsSilver}" Value="True">
                <Setter Property="Background" Value="Silver" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have a XAML code like this: <Style TargetType={x:Type ListBoxItem}> <Setter Property=Template>
I have a listbox where the items contain checkboxes: <ListBox Style={StaticResource CheckBoxListStyle} Name=EditListBox> <ListBox.ItemTemplate>
I have a templated ListBox : <ListBox Grid.Row=0 Grid.Column=1 Background=Transparent BorderThickness=0 x:Name=mainMenu ItemsSource={Binding Source={x:Static
I have the following code: ListBox.DataSource = DataSet.Tables(table_name).Select(some_criteria = match) ListBox.DisplayMember = name The
With a listbox, I have the following code to extract the item selected: private
I have a list box control: <asp:ListBox runat=server id=lbox autoPostBack=true /> The code behind
I have a ListBox whose ItemsSource is bound to a list of objects. The
I have an array of System.Windows.Controls.Image and I assign it to ListBox.ItemsSource . What's
I have a style for a ListBox . In the ListBox style I have
Using MVVM style I have successfully bound an ObservableCollection<string> to a ListBox , showing

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.