I just started WPF and I'm getting problem for stylling.
I have a style that I use for all TextBlock
in the UserControl
.
<UserControl.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="10" />
</Style>
</UserControl.Resources>
It work great for the TextBlock
in the first StackPanel
but not for the TextBlock
in the TreeView
.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
<TreeView ItemsSource="{Binding Tests}" Grid.Row="2">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type dml:TestCase}" ItemsSource="{Binding Tasks}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</HierarchicalDataTemplate>
<!--Task Template-->
<HierarchicalDataTemplate DataType="{x:Type dml:Task}">
<TextBlock Text="{Binding Name}" />
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
</Grid>
Is there a way to do it without setting style on each TextBlock
in the TreeView
?