Which approach is better for styling windows:
1. Properties in the elements like this:
<StackPanel Width="888" Height="491" Name="LoginBox" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-100,0,0,0">
2. Styles located in a resource dictionary like this:
Window:
<StackPanel Name="LoginBox" Style="{StaticResource LoginBox}">
Dictionary:
<Style x:Key="LoginBox" TargetType="StackPanel">
<Setter Property="Width" Value="888" />
<Setter Property="Height" Value="491" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="-100,0,0,0" />
</Style>
Which approach is going to run faster and which will be easier to edit and etc.
Thanks.
Styles is a great way of grouping properties and should be used whenever you are going to use the same property settings for multiple controls. For example, if all your Labels in your application use the same font family and font weight you should consider using a style. This way you can edit the entire look and feel of an application easily. The more controls that share the same settings the more reason to use a style.
I usually declare the style as close to where it is going to be used as possible. Application wide style go into the Resource Dictionary and styles used in a single control are declared in that control.
Take advantage of style inheritance to create sub styles to further simplify your editing.
See here for good tutorials and explanations.