开发者

Extend Grid, or Can another Panel be adapted?

开发者 https://www.devze.com 2023-03-24 04:55 出处:网络
I\'d like to pick your collective brains If I may, concerning some design questions. I\'m making a sim of a UK IECC railway signalbox, for fun :D

I'd like to pick your collective brains If I may, concerning some design questions. I'm making a sim of a UK IECC railway signalbox, for fun :D

Here's a real life example: http://photos.signallingnotices.org.uk/photo.php?pc=77&p=IMG_7319.JPG It's 80's technology, with simple graphics.

It's essentially a grid of fixed size cells, using a custom bitmapped font.

My version will be using WPF, to allow a lot more flexibility, but still have the same basic look, except the original is paginated over a series of monitors, mine will be one large scrollable\zoomable grid. I'd also like to have the grid be sort of infinite, (At lease in the editor, the sim part wont need it) adding rows\columns as necessary.

My first attempts have used a Grid and Rectangles, just to make it easy for me at first. The rectangles will probably be changed to something lower level, depending on how well it performs.

I am running in to some issues that make me think I could be using something better than Grid.

In the 'editor' mode I should be able to add a new element by using a context menu or selecting an empty cell on the Grid. All the solutions for finding on which cell was selected, seem to involve adding Transparent rectangles to every cell, or hacks involving hit testing, and looping through every cell to check for intersections.

Since I'll be dealing with potentially several 1000's of cells, neither of those solutions would seem to really be appropriate, and make me wonder if a standard grid is the best way to proceed.

I'd also like to be able to drag and drop groups of elements...

The grid has no concept of a 'cell'. I can only get the row\column if there is content in that row\column.

Each cell will only have one visual in it.

So, Is there a better way to do this than a standard grid开发者_StackOverflow社区? Would it be better to create a custom panel, extend an existing one, or is there an existing free 3rd party control that might help? My brain seems to be incapable of trying to imagine it as anything else other than Grid :D


I don't know about 3rd party panels, but I think the Grid is the best option you have.

here's what I'd do:

  • a grid with each cell containing a transparent rectangle (even with 1000s of cells, this won't be an issue, see below)
  • a panel encapsulating the grid (StackPanel for instance, or whatever Panel suits you best, as long as you can attach the IsVirtualizing Property to it)
  • then I'd set VirtualizingPanel.IsVirtualizing = true and VirtualizingPanel.VirtualizationMode = VirtualizationModes.Recycling on this panel, so as to lightened the app's layout.

and Voilà! I don't think you need more than this, and I'm pretty sure you cannot do with less than this without using the "hacks" you mention (though I would not call them "hacks" in this case)

NB: this supposes that your grid will scroll (as I think "1000s" of cells won't fit on your screen). If you intend to have your grid fully displayed on screen, the virtualization is basically useless and you'll have to use either one of the methods you detailed

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号