Which Table/Grid Control in WPF?
Asked Answered
T

1

8

I am looking to display tabular data (tv channels), but with options such as DataGrid/UniformGrid/Table with FlowDocument/etc. I cannot figure out what would be the best option. The main issues is that the cells aren't uniform in size as it varies based on length of time, and I would like to put padding between them as well. Additionally, I need to only be able to display a portion of the table, and allow them to scroll Up/Down/Right to view the rest.

What would be the best WPF Control Option for this? Here is a small illustration of what I am going for. The white square in the upper left is what I would want to display at start, and allow them to scroll to the rest of it.

enter image description here

Tourane answered 12/8, 2012 at 17:4 Comment(1)
what about a wrap panel, you can add a scroll viewer to it create the scrolling, and as long as you put your screen in order and have the same height the width and placement issue would be solved by the panelPhilippine
P
3

There are several ways to accomplish what you're trying to do here. If performance is not an issue then I would ignore virtualization and try the DockPanel The drawback here is that you would have to add the items in order rather than adding them by row.

Another option would be to use two stack panels (one in each direction). This addresses the adding issue, but requires the use of more panels.

Both of the previous two options would require individual items to have their height/width set.

A final option (depending on how large your grid is), would be to use a Grid with fixed sized rows and columns with items that span rows (using the rowspan property). The drawback of this method is that I don't know of any good way to create this control in xaml for unspecified numbers of rows/columns so you would have to create it in code to get the needed number of rows/columns.

If you have performance issues you could try using the VirtualizingStackPanel. If this still doesn't meet your performance requirements then you will need to subclass the VirtualizingPanel and tailor it to meet your specific needs.

See here for more information on Panel performance.

I suggest trying the two StackPanel method first, then the VirtualizingStackPanel method and finally, if that doesn't work, then try the VirtualizingPanel

Padding is easily accomplished by setting the Margin property on each subcontrol.

For scrolling use the ScrollViewer

Prakrit answered 14/8, 2012 at 19:37 Comment(4)
I would think the StackPanels would be the best approachMaynor
Thank you very much for the great answer. I will go ahead and accept this and award bounty. I am going to use the Stack Panels w/ Scroll Viewer, but would it be best to have 1 vertical stack panel with the channel names on left side, and a horizontal stack panel to the side of each for EPG data, or just a block of horizontal stack panels, 1 for each channel, and include the channel name/icon in that instead?Tourane
@BrettPowell I would probably have an itemscontrol with a stackpanel as the itemspanel (which is the default) for the vertical and then a template with a control for the channel next to a horizontal stackpanel for the shows. This should simplify layout and binding.Prakrit
I think some assumptions can be made. Each cell would represent 30 minutes (or perhaps 15, as some programs can be short, but this is more of an edge case). So, the width of the cells can be assumed based on the data available (the length of the program). Personally, this has me leaning towards stacked stack panels because it makes sense logically.Snowblind

© 2022 - 2024 — McMap. All rights reserved.