WPF : Creating a scalable glass button in Blend
It’s amazing how a simple effect can transform an application. I have tried to find ways to create a simple glass effect as quickly as possible and with as few brushes and layers as possible to aid in render performance, particularly for Windows mobile 7. My previous attempts looked more like a pipe than glass and involved too many brushes. I have managed to get mine down to two brushes. I think i could get it down further and just use colour substitution but that’s for another post! So here is how I am currently doing it…
Step 1 – Create the first rectangle
Start with a blank user control and ensure you have a layout root grid. This will be very important for the scaling later on.
Create a new rectangle in your required dimensions, in my case its 150 x 50 pixels. Set the fill to a gradient fill maintaining the default gradient. Set the first colour to Black and the second colour to a dark grey, i have used #FF454444 as the dark grey. Set the corner radius to 3 for both x and y.
Step 2 – Create the glass effect rectangle.
The next step is to create the inner rectangle which will give us the glass effect. To do this simply copy the previous rectangle and paste. For now we just want to shrink it so we can get the look right and feel right. Shrink the inner rectangle so that it’s just under half the height of the first rectangle and so that there is a nice gap on either side. Change the gradient colours to white and set the Alpha of the first colour to 10 and the second to 75.
Step 3 – Make the button
Now it’s time to make a Button out of the rectangles we have. First we need to group everything into a Grid. So right click and select “Group Into” and select “Grid” or Ctrl + G.
Now select “Tools” -> “Make into control” and select the button control. Give the template a name.
You should now see the button text appear in the centre of the control. This will also put you in template edit mode. You will need to either double click on the canvas or click the ‘Button’ element at the top of the designer. This is so that You can set the font size and colour of the button to the desired settings. I have set them to 23 and White.
Step 4 – Make the button scalable
You should now have something that looks like a button however if you try to scale it the elements won’t stay in proportion to the height and width of the actual button.
The Easiest way to get around this is to place the elements into a layout element that scales its content. I find the Grid makes the most sense so enter template edit mode by right clicking the control and selecting “Edit Template” -> “Edit Current”.
Select the Grid you grouped the elements into earlier from the “Objects and Timeline” toolbar and add to it three columns and three rows. You can do this from the layout tool bar.
Set the column with to 0.025,1 and 0.025 star respectively and the row heights to 0.15, 0.75 and 1 star respectively. This is very important as it is what will retain the relevant proportions of the elements.
Place the background rectangle and the content presenter in row and column 0 with row span and column span set to 3. Place the glassy rectangle in row 1 column 1 and now set the glassy margins to 0 and its height and width to Auto with horizontal and vertical alignment set to stretch.
Make sure that the Content element is a layer behind the glassy rectangle by moving it in the Objects and Timeline toolbar. This is so that the whole button will appear to be glass including the text. You can test this is the case by changing the foreground of the button to a shade that will make this clear to see.
That’s it. You should now have a very simple scalable glass button.
Post Comment
6XxKUP You are my inhalation , I own few web logs and very sporadically run out from to brand.
9OUGoy Just wanna input that you have a very nice web site , I like the layout it really stands out.
XX2zLX Some really prime posts on this web site , saved to bookmarks.
MG2Ejt Way cool! Some extremely valid points! I appreciate you penning this article plus the rest of the website is really good.
LemXJQ Really enjoyed this article. Really Cool.
DsWETk Thanks for some other magnificent post. Where else may anybody get that kind of info in such a perfect way of writing? I ave a presentation next week, and I am at the search for such info.
cntAjU Modular Kitchens have changed the very idea of kitchen nowadays since it has provided household females with a comfortable yet a classy place in which they may invest their quality time and space.
siCtar ppi claims ireland How can u add a flash slide show to your blogspot?
oWEgdq This site was how do you say it? Relevant!! Finally I ave found something which helped me. Thank you!
CPPIrj Thorn of Girl Great info may be uncovered on this world wide web blog site.
wm9EvO Yahoo results While browsing Yahoo I discovered this page in the results and I didn at think it fit
ezk1eh You ave made some really good points there. I looked on the net for more info about the issue and found most individuals will go along with your views on this site.
wQPEZC Say, you got a nice blog post.Really thank you! Keep writing.
fo3GSq This is very interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your fantastic post. Also, I ave shared your web site in my social networks!
There as definately a great deal to find out about this topic. I really like all the points you have made.
d3vOYc This is very interesting, You are a very skilled blogger. I ave joined your rss feed and look forward to seeking more of your magnificent post. Also, I ave shared your site in my social networks!
yVx7lv
83BE9M Really informative blog post. Really Cool.
HyJoL7 plastic bathroom faucets woud eaily break compared to bronze bathroom faucets-
K7OZsL Awesome article.Thanks Again. Keep writing.
3TEfQA your communal pages like your linkedin profile, Facebook
gfx4HJ Simply wanna tell that this is handy , Thanks for taking your time to write this.
OFeajv I loved your article post.Thanks Again. Want more.
i7VZIY Well I really liked studying it. This information offered by you is very practical for proper planning.
YKuvQ8 Hey there, You have done an excellent job. I will certainly digg it and personally suggest to my friends. I am confident they'll be benefited from this web site.
MYH4We whoah this blog is fantastic i love reading your articles. Keep up the good work! You know, a lot of people are searching around for this information, you can help them greatly.
CFvkOH Really enjoyed this blog post, how can I make is so that I receive an email whenever you publish a new update?
Jif6xN Looking forward to reading more. Great article.Really thank you! Keep writing.
Great, thanks for sharing this post.Really looking forward to read more. Awesome.
I really like and appreciate your blog article.Thanks Again. Great.
Very informative article post.Much thanks again. Much obliged.
Thanks again for the blog.Really looking forward to read more.
Really appreciate you sharing this blog post.Much thanks again. Want more.
I appreciate you sharing this post.Thanks Again. Keep writing.
Thanks so much for the post. Cool.
Very informative blog post.Much thanks again. Keep writing.
Thanks again for the article post.Really thank you! Much obliged.
Im grateful for the blog post.Thanks Again. Much obliged.
Major thanks for the blog.Thanks Again. Keep writing.
Very informative post.Thanks Again. Really Great.
Thanks for the blog.Really looking forward to read more. Keep writing.
Fantastic blog article.Thanks Again. Great.
Thanks a lot for the blog. Much obliged.
Great blog post.Thanks Again. Really Great.
Thanks for the post.Really looking forward to read more. Will read on...
Wow, great blog. Cool.
Really informative blog.Really looking forward to read more. Much obliged.
Really informative article.Really looking forward to read more. Keep writing.
Really appreciate you sharing this blog. Will read on...
Thanks so much for the article post. Keep writing.