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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:03:53+00:00 2026-06-01T21:03:53+00:00

I have a StackPanel that I dynamically hide/show items from, and I would like

  • 0

I have a StackPanel that I dynamically hide/show items from, and I would like to make it so that the background property of each item alternates (white and grey). I tried doing it programmatically, but it is quite inefficient as the code that sets the background of each item runs every time an item is hidden/shown. I know that maybe using Styles/Templates could solve this, but for some reason this particular feature of WPF has confused me every time I try to learn it. Could someone please show me how to do this?

Also, I have thought of using ListBox/ListViews rather than StackPanel, but trust me that due to my particular implementation they don’t work as well.

  • 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-01T21:03:54+00:00Added an answer on June 1, 2026 at 9:03 pm

    You can do it with any ItemsControl using triggers on attached property ItemsControl.AlternationIndex (sample – http://dotnetbutchering.blogspot.com/2009/08/how-to-set-wpf-listview-alternate-row.html) but i don’t think it is possible in xaml only with StackPanel. Are you sure doing it programatticaly is slow? I am quite sure it will work fast enough so you don’t need to bother.

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

Sidebar

Related Questions

I have ToggleButtons that are dynamically created based on my datasource. I would like
In WPF 3.5 (with SP1), I have simply StackPanel that I would like to
I have a Stackpanel and want that the items automatically set their sizes regarding
I have a StackPanel that I dynamically change the contents of every 5 minutes
I have a WPF application that I'm trying to dynamically add items to a
I have a bound treeview with an ItemsControl that dynamically creates the treeview items
I have a StackPanel of Image objects that are created and added dynamically. How
I have a tree view. I am creating the tree view items dynamically. Each
I have a WPF StackPanel that looks like this: (some attributes removed that don't
Say I have a StackPanel that gets dynamically filled with copy, changing the Y

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.