Changing the order of properties when controls are added to a WPF Window
When adding new controls to a WPF Window (or other "custom" control), such as a label, the IDE prebuilds such as
<Label Content="Label" Grid.ColumnSpan="2" Grid.Row="6" Grid.RowSpan="2" Height="28" HorizontalAlignment="Left" Margin="54,11,0,0" Name="label1" VerticalAlignment="Top" />
I would like it to change the default order and formatting, such as...
<Label Name="label1"
Content="Label"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Grid.Row="?"
开发者_运维技巧 Grid.Column ="?"
Height="28"/>
Especially as a newbie to WPF, I hate how things are just "thrown" together by the IDE. I like to have the name of controls up front, primary alignment issues, then the where and extras regarding the control.
I Don't know the way of stablish a default order in the properties, but maybe Xaml Markup Styler can be of your interest. It's a plugin for VS that reformat your XAML (contextual menu) and sort the atributes based on their importance (The importance in the opinion of the plugin developer.
Anyway, I'm using this plugin right now and I recomend it.
http://xamlstyler.codeplex.com/
I know this is not exactly what you want, but maybe It's a good partial solution.
in the xaml, the order of the properties does not matter. the visual editor will generate them in the order in which it was coded to generate them. you can reorder them and remove the ones you want (default values will be used, if necessary), for the most part, to your hearts desire.
in your example (for example) you don't need Grid.Row
or Grid.Column
if your label is not a child of a Grid
control. You can leave off the Height
if you want to use the default Height
. Really, the only thing you SHOULD probably set is the Content--but even that is optional.
now, the other thing you can do is add a <style>
to your resources section. by using a <style>
you can set all of the "defaults" to what you want. for example, you can set the background or text color to be the same on every <Label>
or only on the ones you tell to use the style that you create.
here is a pretty decent article on styles and control templates.
精彩评论