XAML – Code Style Best Practices

coding-stylexaml

I started coding WPF applications a several months ago and now I am asking myself if there are some style guides for XAML. I do not need to get explained the benefits of Binding, Converters, Styles, Templates etc. My question is more basically.

Is there an official (or unofficial) „best practice“ about the order of attributes etc:

For instance:

<ComboBox Grid.Column="0" Grid.Row="0"
          Name="CellType"
          ItemsSource="{Binding EditorTypes}"
          SelectedItem="{Binding EditorType}">

Is there something like

  • always attached properties first [last]
  • always declare a column [row] in a Grid, even if there is only one

Are there some rules/guides I should read to make my code look more common?

Best Answer

There is no "official" best practice rules. There is however a Google Group that wants to establish these best practices: https://groups.google.com/group/wpf-disciples/web/wpf-and-xaml-coding-guidelines?hl=en. There even are some propositions on how to organize these files for bigger projects (company scale)

Their propositions look reasonable.

Related Topic