Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Blend add [d:LayoutOverrides="Height"] and should I care?

Tags:

Quite often when coming back to Visual Studio from Expression Blend 3, I see that Blend has helpfully added a "d:LayoutOverrides" property to my XAML. Growing up with ASP.NET designers, I naturally distrust anything I wouldn't type myself, so remove them as soon as I see them.

I know that "d:" properties are designer-only and don't impact runtime, but can anyone offer any insight into what this property does and why Blend would be so insistent that I have them all over my markup?

<Border d:LayoutOverrides="Height" /> 
like image 542
Brad Tutterow Avatar asked Sep 11 '09 14:09

Brad Tutterow


2 Answers

That's just there so that Blend knows how to display your XAML in design mode. Specifically, if you've got a fluid layout that stretches to fill its container, there's no clear way for Blend to know how tall your design should be; LayoutOverrides defines that.

Those LayoutOverride settings entries are added when you (or another person running Blend) manually resizes the elements in the design surface. If you're seeing them all over your code (such as in a Border element):

  1. You can usually delete them without any noticable affect
  2. You might look at how you're using Blend - specifically, you should size the parent cotainer to a good size (UserControl / LayoutRoot), then set the child sizes based on fluid layout - e.g. padding and margin or * sizes

Note that Blend's ignorable attributes are stripped out at compile time and have no affect on your application's performance. So while you may want to remove them to improve code readability, they don't affect how your application runs.

like image 130
Jon Galloway Avatar answered Sep 21 '22 05:09

Jon Galloway


d:LayoutOverrides

If a property is set to a fixed value at runtime, but you want to override it at designtime, you can use the d:LayoutOverrides attribute. All properties that should be ignored at designtime can be listed, separated by a semicolon.

(source: http://wpftutorial.net/DesigntimeVsRuntime.html)

like image 29
George Birbilis Avatar answered Sep 20 '22 05:09

George Birbilis