简体   繁体   中英

WPF grid XAML layout

I am writing my UI mostly in XAML without a WYSIWYG editor.

In Grids you can do:

  <TextBox  Grid.Column="0" Grid.Row="0" ...

When creating a Grid coming from a HTML background I have been doing:

<TextBox  Grid.Column="0" Grid.Row="0">
<Label Grid.Column="1" Grid.Row="0">

<TextBox  Grid.Column="0" Grid.Row="1">
<Label Grid.Column="1" Grid.Row="1">

But ordering the XAML by columns just seems neater:

<TextBox  Grid.Column="0" Grid.Row="0">
<TextBox  Grid.Column="0" Grid.Row="1">

<Label Grid.Column="1" Grid.Row="0">
<Label Grid.Column="1" Grid.Row="1">

seems neater.

I'm just curious, how everyone else is doing it?

That depends on whether or not you want controls to be on top of each other, that's the only significant difference when re-ordering them like that.

In XAML Controls are ordered ( the z-index ) as you add them, meaning that if you first add <TextBox> and then <Label> , the <Label> can be on-top of the <TextBox> and not the other way around.

However in your case, it is much nicer to add them ordered by row then column then z-index.

That's the way I would do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM