I currently have a big lump of XAML that I am struggling to refactor.
<DataGrid x:Name="CurrentConfigDataGrid" ItemsSource="{Binding}" >
<DataGrid.Resources>
<ResourceDictionary Source="../ResourceDictionaries/MergedDictionary.xaml" />
</DataGrid.Resources>
<DataGrid.ItemContainerStyle>
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource {x:Type DataGridRow}}" />
</DataGrid.ItemContainerStyle>
<DataGrid.Columns>
<DataGridCheckBoxColumn Width="25">
</DataGridCheckBoxColumn>
<DataGridTemplateColumn Width="80" CanUserResize="False" CanUserSort="False" >
<DataGridTemplateColumn.Header>
<Label Content="Type" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}" />
</DataTemplate.Resources>
<TextBlock Text="{Binding Type}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="150" CanUserResize="False" CanUserSort="False" >
<DataGridTemplateColumn.Header>
<Label Content="Version / Date" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}" />
</DataTemplate.Resources>
<TextBlock Text="{Binding Version}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="150" CanUserResize="False" CanUserSort="False" >
<DataGridTemplateColumn.Header>
<Label Content="GUID" />
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DataTemplate.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}" />
</DataTemplate.Resources>
<TextBlock Text="{Binding GUID}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
How do I pull out the standard "TextBlock" style so it will be automatically picked up? I reference my MergedDictionary at the start, but this doesn't automatically convert the styles in the DataGrid to that of the textBlock unless I manually specify them... which means I need a DataGirdTemplateColumn, and then a Template, etc.
How is best to refactor?
Does this work...?
Technically, if you create a Style in your Resources, with no Key but with a TargetType, it should be applied automatically to all controls of that type that have no explicit Style set.