How to Add a Datagrid in WPF

–Datagrid in WPF

1) Create a Datagrid

<DataGrid x:Name=”uxHistory” AutoGenerateColumns=”False” IsReadOnly=”True” Margin=”0,5,0,0″>

</DataGrid>

2) then define datagrid column

<DataGrid.Columns>
</DataGrid.Columns>

3) Now add DataGridTemplateColumn field to actually specify data related to each column

<DataGridTemplateColumn Header=”{DynamicResource ResourceKey=RegistrationSearchControl.ApplicationNumber.TextBlock.Text}” Width=”Auto”>
</DataGridTemplateColumn>

4)
<DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn.CellTemplate>

5) <DataTemplate></DataTemplate>

6) and finally inside of datatemplate we add text box etc
<DataTemplate>
<TextBlock TextWrapping=”Wrap” Text=”{Binding Path=ApplicationNumber}” VerticalAlignment=”Center” Margin=”2,0,0,0″/>
</DataTemplate>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>