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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:15:45+00:00 2026-05-10T23:15:45+00:00

I have a WPF ListBox bound to a data object. Inside the listbox are

  • 0

I have a WPF ListBox bound to a data object. Inside the listbox are a series of images with text. It is layed out in a horizontal fashion, and mousing over the left or right sides of the box scroll the items left or right respectively.

let’s say there are 20 items in the listbox. I’m trying to figure out how when I hit position 19 item (0 based) that I can cycle the box and start the collection over, so that it goes 1 -19 and so on. It would need to also cycle the other way, so that if you were on item 0, and scrolled left, you would get 19.

I’ve tried the KeyboardNavigation.DirectionalNavigation=’Cycle’ but that doesnt’ seem to do anything for me, and I was grasping at straws since this has nothing to do with the keyboard, it’s all mouse based.

        <ListBox ItemsSource='{Binding Source={StaticResource WPFApparelCollection}}' Margin='24,-7,39,-19' ScrollViewer.VerticalScrollBarVisibility='Hidden' ScrollViewer.HorizontalScrollBarVisibility='Hidden' SelectionMode='Single' x:Name='list1' MouseLeave='List1_MouseLeave' MouseMove='List1_MouseMove' Style='{DynamicResource ListBoxStyle1}' Background='Transparent' BorderThickness='0'>             <ListBox.Resources>                 <!-- override the system brushes so that selected items are transparent whether the ListBox has focus or not -->                 <SolidColorBrush x:Key='{x:Static SystemColors.HighlightBrushKey}' Color='Transparent' />                 <SolidColorBrush x:Key='{x:Static SystemColors.ControlBrushKey}' Color='Transparent' />                 <SolidColorBrush x:Key='{x:Static SystemColors.HighlightTextBrushKey}' Color='Black' />             </ListBox.Resources>             <ListBox.ItemContainerStyle>                 <Style TargetType='{x:Type ListBoxItem}'>                     <Setter Property='Background' Value='Transparent' />                     <Setter Property='HorizontalContentAlignment' Value='{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}' />                     <Setter Property='VerticalContentAlignment' Value='{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}' />                     <Setter Property='Padding' Value='20,10,20,10' />                     <Setter Property='Template'>                         <Setter.Value>                             <ControlTemplate TargetType='{x:Type ListBoxItem}'>                                 <Border x:Name='Bd' SnapsToDevicePixels='true' Background='Transparent' BorderBrush='{TemplateBinding BorderBrush}' BorderThickness='{TemplateBinding BorderThickness}' Padding='{TemplateBinding Padding}'>                                     <ContentPresenter HorizontalAlignment='{TemplateBinding HorizontalContentAlignment}' VerticalAlignment='{TemplateBinding VerticalContentAlignment}' SnapsToDevicePixels='{TemplateBinding SnapsToDevicePixels}' />                                 </Border>                                 <ControlTemplate.Triggers>                                     <Trigger Property='IsSelected' Value='true'>                                         <Setter Property='Background' TargetName='Bd' Value='Transparent' />                                         <Setter Property='Foreground' Value='{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}' />                                     </Trigger>                                     <MultiTrigger>                                         <MultiTrigger.Conditions>                                             <Condition Property='IsSelected' Value='true' />                                             <Condition Property='Selector.IsSelectionActive' Value='false' />                                         </MultiTrigger.Conditions>                                         <Setter Property='Background' TargetName='Bd' Value='{DynamicResource {x:Static SystemColors.ControlBrushKey}}' />                                         <Setter Property='Foreground' Value='{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}' />                                     </MultiTrigger>                                     <Trigger Property='IsEnabled' Value='false'>                                         <Setter Property='Foreground' Value='{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}' />                                     </Trigger>                                 </ControlTemplate.Triggers>                             </ControlTemplate>                         </Setter.Value>                     </Setter>                 </Style>             </ListBox.ItemContainerStyle>             <ListBox.ItemsPanel>                 <ItemsPanelTemplate>                     <VirtualizingStackPanel Orientation='Horizontal' IsItemsHost='True' />                 </ItemsPanelTemplate>             </ListBox.ItemsPanel>             <ListBox.ItemTemplate>                 <DataTemplate>                     <StackPanel Orientation='Vertical'>                         <Image Source='{Binding Image}' MouseLeave='Image_MouseLeave' MouseEnter='Image_MouseEnter' Cursor='Hand' Tag='{Binding Link}' MouseLeftButtonDown='Image_MouseLeftButtonDown' VerticalAlignment='Top' HorizontalAlignment='Left'></Image>                         <Label Content='{Binding Name}' Cursor='Hand' Tag='{Binding Link}' MouseLeftButtonDown='Label_MouseLeftButtonDown' VerticalAlignment='Bottom' Foreground='White' Style='{StaticResource Gotham-Medium}' FontSize='8pt' HorizontalAlignment='Center' />                     </StackPanel>                 </DataTemplate>             </ListBox.ItemTemplate>         </ListBox> 
  • 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. 2026-05-10T23:15:46+00:00Added an answer on May 10, 2026 at 11:15 pm

    The issue here is not really with the ListBox, but with the ScrollViewer inside its control template; therefore to make the items cycle you’ll need to change the ScrollViewer in some way. I have written a control that derives from ScrollViewer that cycles in a vertical direction… but it should be easy to see how to make it work horizontally too.

    public class CyclicScrollViewer : ScrollViewer {     public CyclicScrollViewer()     {         this.CommandBindings.Add(new CommandBinding(ScrollBar.LineUpCommand, LineCommandExecuted));         this.CommandBindings.Add(new CommandBinding(ScrollBar.LineDownCommand, LineCommandExecuted));     }      private void LineCommandExecuted(object sender, ExecutedRoutedEventArgs e)     {         if (e.Command == ScrollBar.LineUpCommand)         {             if (this.VerticalOffset == 0)                 this.ScrollToEnd();             else                 this.LineUp();         }          if (e.Command == ScrollBar.LineDownCommand)         {             if (this.VerticalOffset == this.ScrollableHeight)                 this.ScrollToTop();             else                 this.LineDown();         }     } } 

    The ScrollTo… and Line… methods already exist on the ScrollViewer making the coding pretty simple. All I’m doing here is checking the current offset against the bounds of the viewer before scrolling.

    The next step is to insert the new ScrollViewer into the control template for the target control, in this case the ListBox. Here’s a XAML snippet to demonstrate this.

            <ControlTemplate x:Key='{x:Type ListBox}' TargetType='ListBox'>             ...                 <l:CyclicScrollViewer                      Padding='{TemplateBinding Control.Padding}'                      Focusable='False'>                     <ItemsPresenter ... />                 </l:CyclicScrollViewer>             ...         </ControlTemplate> 

    I’ve posted a sample application that uses this code here. This sample does not have keyboard support, but that can be simply added by overriding the OnKeyDown method and executing the appropriate Line… commands. I hope this helps.

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

Sidebar

Related Questions

I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,
I have a WPF listbox which displays messages. It contains an avatar on the
Each item in a WPF ListBox control seems to have a bit of left
I have a WPF TabControl with two TabItems. Each TabItem contains a ListBox with
I have a WPF app with a listbox and a contentcontrol. The contentcontrol content
My WPF Listbox should have two columns. The one on the right should have
I have a weird problem with a ListBox in Wpf, where I have a
I have a ListBox control in WPF which contains items of variable height (predominantly
I have a WPF project and I'm trying to setup a NAnt build script
I have a WPF application in VS 2008 with some web service references. For

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.