La définition du style par défaut sur un TextBlock entraîne également le paramétrage du style dans le libellé et dans les autres contrôles. Cela n'arrive que si vous mettez les styles dans les ressources de l'application, quand je place le style dans les ressources de la fenêtre, tout va bien.WPF La définition du style par défaut sur un TextBlock remplace le style d'une étiquette
J'ai également constaté que VS 2008 Designer et XamlPadX affichent l'étiquette comme vous pouvez l'imaginer, mais le problème ne se produit que si vous exécutez l'application dans la vraie vie.
<Application x:Class="WpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="8"/>
</Style>
<Style x:Key="Title" TargetType="Label">
<Setter Property="FontSize" Value="32"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
<Window x:Class="WpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300"
Title="Window1"
Width="300">
<StackPanel>
<TextBlock Text="TextBlock No Style" Style="{x:Null}"/>
<Label Content="Label No Style" Style="{x:Null}"/>
<TextBlock Text="Default TextBlock"/>
<Label Content="Default Label" Style="{StaticResource Title}"/>
</StackPanel>
</Window>
Le code ci-dessus affiche:
TextBlock No Style - Default font size (As you would expect)
Label No Style - Size 5 font size (How did this happen?)
Default TextBlock - Size 5 font size (As expected by my style)
Default Label - Size 5 font size (How did this happen?)