tags:

views:

34

answers:

1

Hi all,

I am using horizontal list view in marquee list. Which is keep moving from right to left.

My code is :

        double height = canMain.ActualHeight - marqueeList.ActualHeight;
        marqueeList.Margin = new Thickness(0, 0, 0, 0);
        doubleAnimation.From = -marqueeList.ActualWidth;
        doubleAnimation.To = canMain.ActualWidth;
        doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
        doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(_marqueeTimeInSeconds));
        Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Right)"));
        _storyBoard.Children.Add(doubleAnimation);
        _storyBoard.Begin(marqueeList, true)

But once it move completely there is blank space come until again the first item is not come. I want to remove the blank space between first items to last item.(Like circullar)

Please help me on this…its urgent!!!

+1  A: 

If your ListView items don't need mouse or keyboard interaction you can just put a Rectangle with a visual brush to the right of it:

<DockPanel Name="marqueeListTwice">
  <ListView Name="marqueeList" .../>
  <Rectangle Height="{Binding RenderHeight,ElementName=marqueeList}"
               Width="{Binding RenderWidth,ElementName=marqueeList}">
    <Rectangle.Fill>
      <VisualBrush Visual="{Binding ElementName=marqueeList}" />
    </Rectangle.Fill>
  </Rectangle>
</DockPanel>

This DockPanel will now appear to have two side-by-side copies of the ListView: The one on the left is the real one, and the one on the right is a Rectangle painted with a picture of it. The VisualBrush painting mechanism is "perfect" in the sense that you cannot tell the painted copy from the real thing.

Now you can animate the "marqueeListTwice" control across your canvas for a distance of marqueeList.ActualWidth. When you get to the end you will appear to be looking at the first item but you will actually be looking at the image of it painted on the rectangle. When you move back to 0, the "real" first item will be visible again but since it is visually identical you won't get so much as a flicker.

If you need individual items to interact with the mouse during the pan, this solution won't work because the painted rectangle won't respond as expected: You'll need logic to slide individual items around instead of sliding a ListView containing all of them. You can still use an animation to do it: Just animate a property of your container Window or UserControl, and use that to calculate your item positioning.

Ray Burns
Thanks for ur reply ! but i need to use mouse on my marquee list so is there no other way to achive it ??
ashish semwal
Yes. As I mention in the last paragraph you can use your own logic to slide items exactly where you want them instead of using a ListView to do it for you. I would do this with a custom Panel subclass. The custom panel would have a property "Offset" which would might count from 0 to 1 or from 0 to ItemCount. This property would have the InvalidatesArrange flag set. Then in your ArrangeOverride you would compute the locations of all children by using the Offset value, children sizes, etc. The details of this calculation depend on your specific needs.
Ray Burns
To get data binding to work with a custom panel, you can keep using a ListView and set its ItemsPanel property to an ItemsPanelTemplate that contains an instance of your custom panel class with its Offset property bound as desired. Then just animate the property to which this Offset is bound, which will cause the Offset property to update and the ArrangeOverride to recalculate the positions.
Ray Burns
Since more than one item will display at once, in your ArrangeOverride you can compute which items are visible (including partially visible) and compute their positions. (Sometimes this will be the last item and the first item.) All other items can be given locations that put them outside the viewport, then as long as clipping is enabled you won't see them.
Ray Burns