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 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

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I understood the question correctly, this might be the… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer They are more secure than what you are doing. Your… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer Something you may want to try to rule out window… May 11, 2026 at 11:34 pm

Related Questions

I'm new to WPF and data binding so hopefully I can explain the problem
I have ObservableCollection<Foo> that is bound to an ItemsControl (basically displaying a list). Foo
I've got a wpf listbox that is bound to a datatable. At some times,
I have an instance of ObservableCollection bound to a WPF listbox with two separate

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.