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.
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
来源:https://stackoverflow.com/questions/11924073/which-table-grid-control-in-wpf