# Is this a good user control layout for WPF?

Below is a code snippet of how I have been laying out my WPF control XAML. I do it mainly because I get intellisense in the editor and I can change the implementation of the viewmodel and push the layout into a resource file.

However, I am not sure whether you gurus have a better insight into why I should not do this?

I'm just after a critique really.

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Styles/BaseStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>

<DataTemplate x:Key="LayoutRoot"
DataType="{x:Type ns:IViewModel}">

<Grid Height="200" Width="300">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Label Content="Some Label" Style="{StaticResource BoldLabel}" Margin="5, 0"
Target="{Binding ElementName=Lcb1}"/>

<endorsements:LimitComboBox Grid.Row="0" Grid.Column="1" x:Name="Lcb1"
Limit="{Binding SomeData}" />

<Label Grid.Row="1" Grid.Column="0" Content="Some Other Label"
Style="{StaticResource BoldLabel}" Margin="5, 0" Target={Binding ElementName=Lcb2/>

<endorsements:LimitComboBox Grid.Row="0" Grid.Column="1" x:Name="Lcb2"
Limit="{Binding SomeOtherData}" />

<StackPanel Grid.Row="3" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Right" Grid.ColumnSpan="2">
<Button Content="OK" Command="{Binding ApplyCommand}" IsDefault="True"/>
<Button Content="Cancel" IsCancel="True"/>
</StackPanel>
</Grid>
</DataTemplate>
</ResourceDictionary>


• Could you explain how is this user control meant to be used? – svick Dec 5 '13 at 17:34
• It not so much about what the control does, but more about how to layout the markup. Instead of putting the markup directly into the body, I am placing it in a data template which may or may not be in the resources tag, then using a content presenter to display. – hiding.ape Dec 9 '13 at 13:20

• How exactly would another kind of panel help here? I think that Grid is ideal for this kind of label-value UIs. – svick Dec 5 '13 at 17:37