Silverlight Nine Grid
I was recently working on a project where I ran into a need for a nice nine grid (or scale 9 grid) and realized that with some of the new additions in Silverlight 3 and Blend 3 that one could put together a pretty sweet solution based on pixel shaders and the new design-time extensibility in Blend.
Nine Grids
Just in case everyone isn’t aware of what a nine grid is, it’s a technique for splitting up an image into 9 pieces then scaling those pieces to simulate layout-aware resizing rather than uniform scaling. Nine grids are very useful because they allow graceful resizing of otherwise non-resizable images.
Normally nine grids are done using either one image duplicated, scaled and cropped into 9 parts but I realized that this could be done much more elegantly with a single shader to handle the appropriate stretching. The real big benefit of using an effect is that vector path data from tools such as Illustrator can be nine-gridded in addition to images. A pixel shader also results in a much lower framework element count which helps keep control instantiation time zippy.
Design-Time
Using Blend 3’s new design-time extensions I was also able to put together a solid editing experience complete with adorners on the design-surface- makes it quick and easy to configure.
Labels: C#, ninegrid, Scale9, Silverlight
12 Comments:
Wonderful. There is an approximately 100% chance that I will use this in a future project. Does it work in WPF too?
Cool that it sounds useful!
I haven't done the WPF version yet but it shouldn't be too difficult. It sounds like it'd be useful so I'll see what I can do.
This looks great. Where can I find the download link?
Download link is at the bottom-
http://blois.us/Silverlight/Scale9/Scale9.zip
Amazing. Especially seeing it in action on the design surface. Amazing.
So how do you install and use it?
This is really great thanks. I tried it out with a vector background but unfortunately (and I guess as expected) you lose all the resizable vectory goodness and so in my case the result was pixelated and unusable. I tried making the original vector huge and wrapping it all in a grid with a scale transform to reduce it and this helped somewhat.
You are the man!!! This is suuuper useful. Would you convert this to WPF or explain briefly how to do that? Thanx a lot.
I'm attempting to use just the ShaderEffect, without using blend (everything is loaded at runtime in my project so design-time doesn't really exist). Do you think this is going to be doable?
How hard would it be to add an option to "tile" the middle pieces instead of "stretching" them?
When running in Blend I'm getting an error 'The component 'NineGrid.Design.UI.NineGridAdorner2' does not have a resource identified by the URI '/NineGrid.Design.UI;component/ninegridadorner2.xaml'
Any ideas?
Thanks
Thanks. Just getting started on a UI to replace an older pure html on. This could be a great addition to a scale and center behaviour.
Post a Comment
<< Home