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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:53:04+00:00 2026-05-15T07:53:04+00:00

Silverlight does not support Alternating Item Templates in an ItemsControl. I have a few

  • 0

Silverlight does not support Alternating Item Templates in an ItemsControl. I have a few ideas in mind as to how to accomplish this, but to avoid polluting the potential answers, I’ll leave them out.

The idea is the same as a normal ItemTemplate in that it won’t depend on anything in the bound data context to function. I would like the functionality to remain in the View (assuming MVVM)

If you had to design a method of providing alternating templates (and I mean a full data template) for an ItemsControl, how would you accomplish this?

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

    Extend ItemsControl and in the PrepareContainerForItemOverride override you can apply alternating templates.

            protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
        {
            if (!object.ReferenceEquals(element, item))
            {
                ContentPresenter presenter = element as ContentPresenter;
                ContentControl control = null;
                if (presenter == null)
                {
                    control = element as ContentControl;
                    if (control == null)
                    {
                        return;
                    }
                }
                DataTemplate itemTemplate = null;
                if ((this.ItemTemplate != null) && (this.DisplayMemberPath != null))
                {
                    throw new InvalidOperationException("Cannot set ItemTemplate and DisplayMemberPath simultaneously");
                }
                if (!(item is UIElement))
                {
                    if (this.ItemTemplate != null)
                    {
                        if(this.AlternateItemTemplate != null && ((alternationIndex % 2)) == 1)
                            itemTemplate = this.AlternateItemTemplate;
                        else
                        itemTemplate = this.ItemTemplate;
                        alternationIndex++;
                    }
                }
                if (presenter != null)
                {
                    if (itemTemplate != null)
                    {
                        presenter.Content = item;
                        presenter.ContentTemplate = itemTemplate;
                    }
                    else
                    {
                        presenter.SetBinding(ContentControl.ContentProperty, new Binding(this.DisplayMemberPath));
                    }
                }
                else
                {
                    control.Content = item;
                    control.ContentTemplate = itemTemplate;
                }
            }
        }
    

    The way I’m using alternationIndex is not very accurate and would need to be changed, but otherwise this should work.

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

Sidebar

Related Questions

Since silverlight does not have any support for DataSets/DataTables, what would be the best
.NET 1.0-4.0 supports it but Silverlight/WindowsPhone does not. Does WinRT support assembly binding redirection?
It is said here: http://msdn.microsoft.com/en-us/library/cc903925(VS.95).aspx Silverlight does not support dynamic resources. All resource references
I have a silverlight application, which requires charts with printing. As silverlight does not
The IDictionary<TKey, TValue> in .NET 4 / Silverlight 4 does not support covariance, i.e.
I heard Silverlight support high quality definition video, which flash does not support. Is
Silverlight does not provide perfmon counters for GC. How do i get GC Information?
CLR profiler does not seem to work with the Silverlight CLR. Does another memory
Does silverlight support the remoting functionality of the .net framework?
Does the silverlight clr support access to a sql compact database placed in the

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.