I have seen both of these forms:
<TextBox
Name="someTextBox"
Width="50"
Height="60" >
Some Text
</TextBox>
Advantages
sibling1
's attributes indented 8 spaces, while sibling2
's attributes are indented 9 spaces.Disadvantages
<TextBox Name="someTextBox"
Height="60"
Width="50" >
Some Text
</TextBox>
Advantages
Disadvantages
In short, both work (and both are supported by Visual Studio). I lean towards style #1, but the most important thing would be that I am consistent with other developers. Is one of these styles more commonly used?
I don't think there is an accepted style.
But since the structure of XAML is very different from the structure of normal imperative code, I think a different approach might be better.
I prefer a style you didn't even mention: usualy have all properties on one line. If that line gets too long, split it, preferably in a way that makes sense. So, for example, something like:
<TextBox Name="someTextBox"
Width="50" Height="60">
Some Text
</TextBox>
I don't think high indentation levels are problematic by themselves (they are in normal programming, but that's something else).
Personally, I prefer having all properties in one line of the XAML, just when I write HTML or XML. I think this may be due to the fact that I always have word wrapping enabled in Visual Studio, and have trained my eyes to read it.
Looking at both of the styles you have provided, they are actually harder for me to read.
If I had to choose though, I would pick style 2 for its readability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With