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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:29:42+00:00 2026-05-14T00:29:42+00:00

Is it possible to continue the alteration styles in a gridview even when there

  • 0

Is it possible to continue the alteration styles in a gridview even when there are no items?

alt text

As you can see, after the last item, the pattern stops.

  • 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-14T00:29:42+00:00Added an answer on May 14, 2026 at 12:29 am

    Yes, WPF provides a rather elegant way to implement this because its templating mechanism allows you to fill the unused area in a GridView with whatever you like.

    All you need to do is modify the ListView template to paint the unused section of the with a VisualBrush that typically consists of two GridViewItems stacked vertically (in the general case it will be AlternationCount GridViewItems).

    The only complexity is choosing which color to start with when painting the unused section of the ScrollViewer. This is calculated as Items.Count modulo AlternationCount. The solution is to create a simple Control that does this calculation and use it in our ListView template. For the sake of my explanation I will call the control “ContinueAlternation”.

    The ListView template which would be mostly the default template with a local:ContinueAlternation control added below the ScrollViewer using a DockPanel, like this:

    <ControlTemplate TargetType="{x:Type ListView}">
      <Border BorderThickness="{TemplateBinding BorderThickness}"
              BorderBrush="{TemplateBinding BorderBrush}"
              Background="{TemplateBinding Background}"
              SnapsToDevicePixels="True">
        <DockPanel>
          <ScrollViewer DockPanel.Dock="Top"
                        Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}"
                        Padding="{TemplateBinding Padding}">
            <ItemsPresenter SnapsToDevicePixels="True" />
          </ScrollViewer>
    
          <local:ContinueAlternation
            ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
            AlternationCount="{TemplateBinding AlternationCount}"
            ItemsCount="{Binding Items.Count,
                              RelativeSource={RelativeSource TemplatedParent}}" />
    
        </DockPanel>
      </Border>
    </ControlTemplate>
    

    The ContinueAlternation control will be displayed as a Rectangle painted with a tiled VisualBrush containing an ItemsControl that shows dummy rows, as follows:

    <ControlTemplate TargetType="{x:Type local:ContinueAlternation}">
      <Rectangle>
        <Rectangle.Fill>
    
          <VisualBrush TileMode="Tile" Stretch="None"
                       ViewPortUnits="Absolute"
                       ViewPort="{TemplateBinding ViewportSize}">
    
            <ItemsControl x:Name="PART_ItemsControl"
                          ItemsSource="{Binding}" />
          </VisualBrush>
        </Rectangle.Fill>
      </Rectangle>
    </ControlTemplate>
    

    The DataContext here will be an array of dummy ListViewItem generated in code-behind from the given AlternationCount and ItemsCount:

    public class ContinueAlternation
    {
      public Style ItemsContainerStyle ... // Declare as DependencyProperty using propdp snippet
      public int AlternationCount ... // Declare as DependencyProperty using propdp snippet
      public int ItemsCount ... // Declare as DependencyProperty using propdp snippet
    
      protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
      {
        if(e.Property==ItemsContainerStyleProperty ||
           e.Property==AlternationCountProperty ||
           e.Property==ItemsCountProperty)
        {
          // Here is where we build the items for display
          DataContext =
            from index in Enumerable.Range(ItemsCount,
                                           ItemsCount + AlternationCount)
            select BuildItem( index % AlternationCount);
        }
      }
      ListViewItem BuildItem(int alternationIndex)
      {
        var item = new ListViewItem { Style = ItemsContainerStyle };
        ItemsControl.SetAlternationIndex(item, alternationIndex);
        return item;
      }
    
      protected override Size MeasureOverride(Size desiredSize)
      {
        var ic = (ItemsControl)GetTemplateChild("PART_ItemsControl");
        ic.Width = desiredSize.Width;
        Size result = base.MeasureOverride(desiredSize);
        ViewportSize = new Size(ic.DesiredSize);
        return result;
      }
      public Size ViewportSize ... // Declare as DependencyProperty using propdp snippet
    }
    

    Note that this same code could be written with PropertyChangedCallback instead of OnPropertyChanged.

    You also need to do something to make sure the blank rows are the desired height. The easiest way to do this is to set either MinHeight or Content in your ItemsContainerStyle. Alternatively ContinueAlternation could set the height when it constructs each ListViewItem.

    I typed all this code off the top of my head, but it is similar to code I’ve written and used before so it ought to work basically as-is.

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

Sidebar

Related Questions

Is it possible to make a double continue and jump to the item after
Possible Duplicate: Continue Execution Only After .each() Completes This question is actually a continuation
Is it possible to continue PHP script execution even if require_once fails? If so,
Is it possible to send 100 Continue HTTP status code, and then later some
Is it possible to continue a hash in PHP? Say for example I start
Possible Duplicate: ‘CONTINUE’ keyword in Oracle 10g PL/SQL I am Using Oracle 9i and
Possible Duplicate: In Linux, how to prevent a background process from being stopped after
Is it possible to request last version of App from Android Market via API
Is it possible to make. jquery ajax success, then continue load page's html? For
Possible Duplicate: goto keyword in java There is no goto in java, right ?

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.