Animating through listbox items in Silverlight 4 - silverlight

I have a ListBox bound to a collection of custom objects. I have an ItemTemplate set up for displaying those items. Each item takes up a large rectangular area, so what I want to do is actually only display one item at a time. After ten seconds, I want to animate (maybe slide in/out or fade in/out) to the next item so that only that one is displayed and so on.
I can't get to grips with how to achieve this, can anyone help please?
Maybe a listbox isn't even the right approach?

If you are not dead set on using a listbox, you can get this effect using a TransitioningContentContol instead. How-to Video here (the control is in system.Windows.Controls.Layout.Toolkit). It is now part of the released toolkit (the video is old).
Part of the demo shows how to emulate exactly the behaviour you are after. You can add a slider to the side if you still want it to look a bit like a listbox (and change the selection in response to the slider value changes).

Related

XAML List/ItemView Background 'Drawing'

within WPF I have created a ListView which displays a list of messages in chronological order using a custom ItemsPanel class which uses the time of the messages to correct space them apart when laying out the items;
Is there an easy way to go one step further and add 'other drawing items', for example a timeline (line, ticks and text), to the background of the ListView which scrolls with it? What's the best approach?
Thanks for your comments, but my solution was to add an ItemsControl which binds to a Timeline collection of integers (one every 100ms) that's sits on top of the ListView (and scrolls with it) which simply has two lines it the ItemTemplate to get the following result:
ListView with added timeline markings

ListView item highlighting

I am designing a code viewer using a virtualized ListView control to display code lines.
Now I want to create a highlight effect when the user clicks a link which takes them to a particular line. I want the target line to be highlighted.
The effect will be either an "underline" appearing (and disappearing) or a semi-transparent overlay (like a marker pen) appearing (and disappearing). The actual graphical effect itself is unimportant, that's not the problem.
What is the best approach to achieve this? I'm not quite sure where to start.
Some technical requirements might be that I need to:
find the right events to react to - or use databinding
obtain the absolute bounding rectangle of the virtualized target item (although when brought into view the item should be available)
absolutely position a canvas effect on top, fade in and fade out
...Ideally some state changes in a view model, a piece of XAML is animated via a triggered storyboard to appear (fade in) above the relevant ListViewItem and then animates away again (fade out). Of course before the fade in, the element must already be correctly positioned over the relevant ListViewItem...
I have worked on a search feature for a Listview where every ListViewItem had few textbocks. When the user types something in a search textbox, all the matches in the listview was supposed to get highlighted.
I created Run objects based on the search string (used Regex to find the match) and then set the Background to some color. Also, held the reference of the ListViewItem in the tag of the Run object which helped me to use call ScrollIntoView. Hope this will be of some help in your case.

slow page trasitions due to databinding

I am making a search app in wp7. Every record's data is bound to a user control. I have introduced an infinite loading instead giving page numbers. So when the number of instances of the UserControl is increased in the screen the transition from one page to another page (like the preview or settings pages) or coming back from that page to the current page is getting slower. I cannot change the design (infinite loading concept).
What are the ways to handle this scenario? How about changing the visibility of the controls? And reference or suggestion will be highly appreciated.
Note I tagged WPF and Silverlight because the binding happens the same way in them, expected those to have dealt with scenarios like these.
EDIT Check this question, which is asked by me. Because of having UserControl's in the listbox the vertical offset is not being maintained. So I had no option other than using ItemsControl with scrollViewer around it. ItemsControl contains a list of 5 - 6 usercontrols which intern have itemsControls inside them, I thought virtualization may not happen in such cases. Am I right?
In WPF, this is done by Virtualization
Using Virtualization, only one copy (or a few copies) of the UserControl actually gets created, and switching to another user control actually just swaps out the DataContext that the control is bound to. It doesn't actually create a new UserControl.
For example, if you have an VirtualizingStackPanel with 100,000 items, and only 10 are visible at a time, it will only render about 14 items (extra items for a scroll buffer). When you scroll, the DataContext behind those 14 controls gets changed, but the actual controls themselves will never get replaced. In contrast, a regular StackPanel would actually render 100,000 items when it gets loaded, which would dramatically decrease the performance of your application.
This question about Virtualizing an ItemsControl can probably get you going in the right direction.
Take a look at this post, I believe the solution provided by Rico is what you are looking for. :)

WPF ListBox does not realise that its items have changed size

I have a ListBox that contains a number of User items that are DataTemplated to appear as UserControls in the ListBox. Each UserControl can be expanded in size. To start with, the ListBox is big enough to display them all in their unexpanded state. The problem that I have is that when a number of these UserControls are expanded together, they extend out of the ListBox's visible area. The ListBox does not recognise this fact and no ScrollBars appear, even when they are set to Visible.
I am using DoubleAnimations to alter the UserControl heights when the user clicks on a button in each one. Is there something that I have to do, or some setting on the ListBox that must be set to get it to register the size changes of the UserControls that represent its items and display ScrollBars when needed?
Edit>>>
I have tracked down the problem to a custom WrapPanel that I am using in the ListBox.ItemsPanel. When I remove it, or replace it with a standard WrapPanel, ScrollBars appear when required. I got the code for the Panel from a good article about creating custom WPF panels. Can anyone see what's missing from the code given in the article and why it might stop the ScrollBars from displaying?
I wonder whether ListBoxes normally do what you are expecting? You might try calling InvalidateMeasure/Layout on the ListBox if you know when the item sizes change, just to see?
I decided to write the custom WrapPanel code again completely and this time it worked correctly! When comparing the new version with the previous version, I could see that a + was missing from a += in a measuring calculation and so the Panel thought that the items were much smaller than they really were... hence no ScrollBars.
So, if you have this problem, check your measuring code carefully.

Creating orderable list in WPF using ListBox (HOWTO or better approach?)

I've got a list of things that I want the user to easily edit the order of. Right now I'm binding them to a ListBox with a custom ItemTemplate. Within that template I have an UP & DOWN button. My goal was to move the item up/down based on the button clicked.
However I'm having trouble associating the button's click event with the actual item in the list. I've seen some folks setup a drag/drop for ordering items but that that would be too complex for this app (it's target user base =1, just me).
I assume this is possible with a ListBox. Maybe someone has a beter idea on how to implement this? It's not a huge set of data... less than 25 items.
The DataContext of the button (of the entire template, thus inherited by the button) is the item itself. Simply cast it to your desired type.

Resources