{"id":743,"date":"2013-09-18T08:00:00","date_gmt":"2013-09-18T08:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/2013\/09\/18\/designing-pixel-perfect-layouts-in-visual-studio-2013-and-blend\/"},"modified":"2019-02-14T15:43:46","modified_gmt":"2019-02-14T23:43:46","slug":"designing-pixel-perfect-layouts-in-visual-studio-2013-and-blend","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/designing-pixel-perfect-layouts-in-visual-studio-2013-and-blend\/","title":{"rendered":"Designing pixel perfect layouts in Visual Studio 2013 and Blend"},"content":{"rendered":"<p>It\u2019s a familiar scenario. You\u2019re developing your application and you\u2019ve got a design in mind. It may have come from a professional designer or a sketch on the back of a cocktail napkin, but you need to move from a concept to a working, implemented design. This can be easier said than done.<\/p>\n<p>When your design calls for the baseline of that text to be exactly 100px from the top, but that baseline is within a control template buried in a custom control, it\u2019s a headache to figure out what value needs to be tweaked to get that precise position. In another case, you want the Image to be exactly 300px wide, but your asset is 260px wide and you plan to skew it horizontally until it\u2019s the right width. You probably don\u2019t want to use trigonometry to figure out the correct angle of skew. Blend has heard the pleas for an easier way to do it, and with Blend for Visual Studio 2013, we\u2019ve implemented some new tools to help you take that design and turn it into a polished, ready to impress app. Let your designers go wild; now you\u2019re ready.<\/p>\n<p>A new Ruler\/Guide system helps you get the pixel perfect accuracy you want. The advanced snapping engine gets everything lined up just the way you need, and the upgraded in-place editing engine helps you fix your control templates and styles without removing you from the environment where they\u2019re being used.<\/p>\n<h2>The Measurement Bar<\/h2>\n<p>The first thing you\u2019re going to see when you open up a Windows Store app in XAML or HTML are the new rulers. Drag a control out on the artboard, or just select some element. You\u2019ll see that the rulers bring up the measurement bar, showing you some valuable information. It\u2019s simple\u2026 how wide\/tall is your element? How much distance is there between your element and the sides of the document? That may not seem like it\u2019s the most valuable, but try this\u2026<\/p>\n<p>Create your Grid app and find out if your Title is exactly where it\u2019s supposed to be. The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/hh872191.aspx\">Windows User Experience guidelines<\/a> say that your baseline should be 100px from the top and 120px from the left. When you select the pageTitle, the values that you see on the measurement bar are the FINAL, rendered measurements. It takes into account the parent containers and render transforms to give you a set of measurements that represents where the control will be at runtime. This even works inside a control or data template. So, next time you\u2019ve got a complex UI and you need to get that control to be exactly 120 pixels from the side of the application, you\u2019ll see why the rulers and measurement bars are powerful tools.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7713.VS2013-Blend-PixelPerfectLayout-Rulers-2.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-222158\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7713.VS2013-Blend-PixelPerfectLayout-Rulers-2.png\" alt=\"the measurement bar\" width=\"752\" height=\"446\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7713.VS2013-Blend-PixelPerfectLayout-Rulers-2.png 752w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7713.VS2013-Blend-PixelPerfectLayout-Rulers-2-300x178.png 300w\" sizes=\"(max-width: 752px) 100vw, 752px\" \/><\/a><\/p>\n<h2>Guides<\/h2>\n<p>Of course, now you might be sitting there, asking yourself if there\u2019s an EASIER way to get controls to a specific location. In your design, you\u2019ve got a logo for your app, and you want that logo near the top right of your app, but with 40px of padding from the top and 100px of padding to the right. You could drag the Image to the general location and nudge it around until you get the desired values, but the guides system makes it MUCH easier.<\/p>\n<p>Put your cursor on the top ruler, click the mouse and drag downward. As soon as you do, Blend will create a guide for you and show you the position relative to the top edge of your application. If you don\u2019t want to try to drag to a specific offset, just click on the value and change it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-222152\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C.png\" alt=\"horizontal guide in blend\" width=\"579\" height=\"234\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C.png 579w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C-300x121.png 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/a><\/p>\n<p>If you do the same thing with the guide on the left, you\u2019re going to see the distance from the left edge of the design surface. In this example, that\u2019s not what you want, so drop the guide somewhere, and click just to the right of the value. A context menu will come and allow you to specify that the guide should be \u201cRight Aligned\u201d. Now, Blend will show you the distance to the right edge. Click on that value, type 100, and you\u2019ve now got a guide that\u2019s showing your distance to the edge you want.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-222152\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C.png\" alt=\"horizontal guide in blend\" width=\"579\" height=\"234\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C.png 579w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/2262.image10_02875F1C-300x121.png 300w\" sizes=\"(max-width: 579px) 100vw, 579px\" \/><\/a><\/p>\n<p>If you really want to see something cool, go to the Device panel and switch from Landscape to Portrait. As soon as you do, the vertical guide will readjust itself to be 100px from the new right edge. The guides will always make sure that their distances are correct, regardless of how you change the device resolution, snapped status or orientation.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/1780.image25_425145A1.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-222154\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/1780.image25_425145A1.png\" alt=\"vertical guide portrait mode blend\" width=\"541\" height=\"438\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/1780.image25_425145A1.png 541w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/1780.image25_425145A1-300x243.png 300w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/a><\/p>\n<p>The other really useful part is that you can snap to the guides, regardless of your scope. Draw a Button in the vicinity of the guides and edit the template on the Button. Within the Button, drag out a Rectangle, and you\u2019ll see that you can snap that Rectangle to the guides, even though you\u2019re inside the control template. This significantly improves the experience of trying to get your controls to line up, regardless of the layout patterns you decide to use.<\/p>\n<h2>Snapping<\/h2>\n<p>The snapping engine in Blend has also gotten a few improvements. If you tried to get your Windows Store elements to line up in older versions of Blend, you may have seen that some controls seem to be 3px off from everything else. You may have also tried to get the baseline of your TextBlock to line up with the baseline of the text in your Button, and found it somewhat challenging.<\/p>\n<p>The default controls for Windows Store apps usually have a focus rectangle built into the control. For instance, when a keyboard user navigates to a Button, it gets a white rectangle placed outside the Button indicating focus. This focus rectangle is built into the layout boundaries of the Button, which is why the adorners for a Button on the design surface seem to be a few pixels away from the edges of the Button instead of directly on it. Having the focus rectangle inside the layout bounds helps prevent you from creating ugly layouts with overlapping rectangles, but it certainly makes it tricky to get that Button to look exactly right.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/6888.clip_image010_31CFEDF2.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-222155\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/6888.clip_image010_31CFEDF2.png\" alt=\"radio buttons\" width=\"349\" height=\"258\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/6888.clip_image010_31CFEDF2.png 349w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/6888.clip_image010_31CFEDF2-300x222.png 300w\" sizes=\"(max-width: 349px) 100vw, 349px\" \/><\/a><\/p>\n<p>In the image above, all four controls have a left padding of 100. The guide is also positioned at 100 to show where you EXPECT all of the controls to be. But, the red rectangle shows how the RadioButton and Button are both offset by 3 pixels. These little discrepancies are the things that are, quite frankly, the types of things that will give your app an unpolished look.<\/p>\n<p>The snapping engine in Blend is now able to ignore the invisible elements of most controls and snap to the visual bounds of the elements instead. To see this, drag a guide 100px from the left edge and move a Button toward the guide until it snaps. Now you\u2019ll see that the element\u2019s visuals snap to the guide instead of the layout boundary. This works when you\u2019re snapping elements to guides or to other elements.<\/p>\n<p>Another improvement in the snapping engine is with text baselines. Drag out a horizontal guide, a Button and a TextBlock. Now, drag the Button and the TextBlock to the horizontal guide and try to get the baselines of their text on the guide. You\u2019ll see that Blend is now able to find text baselines for the common controls, and allows you to snap to them. So, when the Windows guidelines tell you that the baseline of a particular text element is supposed to be 140px from the top, you can create that guide and actually get your baseline exactly at 140px.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7217.VS2013-Blend-PixelPerfectLayout-Baseline-Snap.png\"><img decoding=\"async\" class=\"alignleft size-full wp-image-222156\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7217.VS2013-Blend-PixelPerfectLayout-Baseline-Snap.png\" alt=\"baseline snap\" width=\"1070\" height=\"286\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7217.VS2013-Blend-PixelPerfectLayout-Baseline-Snap.png 1070w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7217.VS2013-Blend-PixelPerfectLayout-Baseline-Snap-300x80.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7217.VS2013-Blend-PixelPerfectLayout-Baseline-Snap-768x205.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/7217.VS2013-Blend-PixelPerfectLayout-Baseline-Snap-1024x274.png 1024w\" sizes=\"(max-width: 1070px) 100vw, 1070px\" \/><\/a><\/p>\n<p>The rulers, guides, and snapping features have all been forged from your feedback. We\u2019re always looking for ways to help users make better apps more easily, and if you\u2019ve got more ideas, we\u2019d love to hear them. Please let us know what\u2019s on your mind. We read all the feedback, whether it comes from replies to this post, <a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\/category\/44115-xaml-tools\">User Voice<\/a> requests, <a href=\"http:\/\/connect.microsoft.com\/VisualStudio\">Connect<\/a> bugs or the Send-A-Smile system in Visual Studio.<\/p>\n<table style=\"width: 663px;\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"127\"><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/3531.image_thumb_6AFF42EE.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2013\/09\/3531.image_thumb_6AFF42EE.png\" alt=\"dante gagne\" width=\"112\" height=\"131\" class=\"alignleft size-full wp-image-222159\" \/><\/a><\/td>\n<td valign=\"top\" width=\"534\"><strong>Dante Gagne<\/strong> is a Program Manager with Microsoft and has devoted the last 11 years of his life to XAML tools. He started as a tester, but eventually brought his passion to helping form the features of both Blend and Visual Studio. Today, his focus is on the design experience and productivity.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s a familiar scenario. You\u2019re developing your application and you\u2019ve got a design in mind. It may have come from a professional designer or a sketch on the back of a cocktail napkin, but you need to move from a concept to a working, implemented design. This can be easier said than done. When your [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[135,137,12,126,133],"class_list":["post-743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-blend","tag-html","tag-visual-studio","tag-visual-studio-2013","tag-xaml"],"acf":[],"blog_post_summary":"<p>It\u2019s a familiar scenario. You\u2019re developing your application and you\u2019ve got a design in mind. It may have come from a professional designer or a sketch on the back of a cocktail napkin, but you need to move from a concept to a working, implemented design. This can be easier said than done. When your [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=743"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/743\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}