Silverlight DataPager - Split Into 3X3? - silverlight

I have a ListBox bound to an observable collection.
I also have a data pager bound to the itemsource of the list box.
I currently have the data pager set to only show up to 3 rows.
How would I go about changing the style ListBox style (or something else) such that I could have a 3X3 display? For example, the first three items in my observable collection would be displayed on the first row of the list box, horizontally next to each other, then the next row would contain the next three items in the observable collection?
Any info would be greatly appreciated.
Thanks.
Chris

It sounds like you want to use an ItemsControl with a WrapPanel (from the Silverlight Toolkit) in the ItemsPanelTemplate.
<ItemsControl xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Here's a short tutorial about the WrapPanel: http://blogs.silverlight.net/blogs/justinangel/archive/2008/11/05/silverlight-toolkit-wrappanel.aspx

Related

WPF Animation on listbox items

Any idea what approach I would follow to get the items of a databound listbox to "fly" into the their position in the listbox similarly to the effect you see when a deck of cards is dealt in those Windows Card Games? (I'm using WPF)
You would need to extend the Panel class and use it as the ItemsPanelTemplate of your ListBox.ItemsPanel property. It's really easy... there's just two methods to override; one to measure the items in the ListBox and one to arrange them. Here is a microsoft article on the subject.
Here is perhaps a more useful article [unfortunately, no longer available] that shows how to animate the items. For your effect, you would simply set the from value on your position animations to be the same location just off the viewable area for each of your items. For example, using a from position of 0, finalSize.Height would mean that each item would slide to its position from the bottom left corner of the ListBox.
You could use your new animated Panel as follows:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<YourXmlNamespace:YourAnimatedPanel AnyCustomProperty="value" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

Silverlight 4 nested ListBox controls performance issue

I am working on a silverlight page that will have a horizontal list box that will contain a list of "cards". Each "card" contains a vertical list box with some text in it. However, I am running into a lot of performance issues. Has anyone experienced any performance issues with nested listboxes in the past?
If its a DataGrid then Paging can give good performance. If its ListBox then we should keep an eye on the count of data binded with listbox.
Are you trying to bind the full list on single shot from server ? Then this will definitely affect the performance.
UI Virtualization might help you. Try to use VirtualizingStackPanel (instead of StackPanel) as the ItemsPanel of your Listbox:
<ListBox>
...
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

Silverlight Animating Control in ListBox

I've got a user control that I'm using as my DataTemplate for all the items in my ListBox. There's an animation in said UserControl that's pretty simple - it just expands a certain ListBox, and it works. The thing is, when I scroll, every Nth item ALSO has the ListBox expanded, where N depends on how big my browser is sized to (in other words, how many items the ListBox is holding at any one time.)
It seems as though new items getting loaded into the listbox as I scroll are tripping over this animation. Is there anything I can do about this?
If your outer ListBox contains only a few items then add this to its Xaml:-
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItesmPanelTemplate>
</ListBox.ItemsPanel>
By default the ListBox uses a VirtualizingStackPanel which only contains concrete instances of ListBoxItem that are currently being displayed. Items a generated as needed by a ItemContainerGenerator which will recycle existing items. I suspect some in there the state of an ListBoxItem is not entirely cleared when re-used to display another item from the ItemsSource.

WPF GridView: "Newspaper" Column?

I'm not sure how else to describe this, outside of calling it a "newspaper" column.
Essentially I have a potentially long list of codes that I want to display in a grid, and I have limited vertical real estate. I would like to show these codes (which are all from the same database column) in multiple columns, maybe 3-5 columns across.
I can absolutely break the data up into separate sources and bind to them separately if that is the best solution, but I thought there might be an easy, built-in way to accomplish this with WPF.
This is actually trivial using a WrapPanel.
For a hard-coded list:
<WrapPanel Orientation="Vertical">
<ItemOne />
<ItemTwo />
...
</WrapPanel>
For a data-bound list:
<ItemsControl ItemsSource="...">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="...">
...
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
If desired you can replace the ItemsControl with a ListBox or make it a ComboBox or whatever. You can use a default template for your data or use a custom template as shown above. You can even use a ListView along with a GridView if you want a multi-column list.
I suspect what you're looking at here is a custom layout panel which has a well defined height and then wraps into the next column. You could then use the ItemsPanelTemplate of the list control to use your new custom panel.
With respect to the development of the panel itself, I would suspect that either wrapping or inheriting from the Grid would be an excellent first choice. The panel could then manage the column definitions itself based on the number of items it contains.
To determine the layout of the individual items, I suspect using the ActualHeight to determine when another item would cause a column to overflow and using that to move to the next column would be the optimal solution. I would imagine using a single vertical stack panel with no border or padding inside each column may make it easier for your to offload the layout to those controls, but I believe you would still wind up having to determine which panel to lay the items out in based on the item heights.

Resizing Listbox Contents according to Listbox dimensions

I am attempting to resize the contents of my listbox according to the listbox itself. This is being done in WPF.
Any ideas on how this might be possible?
I assume when you say "resize" you mean that you want to stretch the items in both directions. To take a default ListBox and stretch the items horizontally all you need is:
<ListBox HorizontalContentAlignment="Stretch"/>
The default is Left so all the ListBoxItems end up pushed to the left and sized individually based on their content.
Vertical stretching requires getting rid of the StackPanel used to do layout for the items because it has no concept of resizing its children in the direction of Orientation. The simplest thing to use is a UniformGrid but you might want something more custom depending on how you want the items to size relative to each other. You'll also need to do the same thing with the VerticalContentAlignment setting (Center by default). So here's one that will stretch items both ways:
<ListBox HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

Resources