Je pense que c'est ce que vous cherchez:
Votre contrôle utilisateur personnalisé "test":
<UserControl x:Class="WpfApplication4.test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<TextBlock>test</TextBlock>
</Grid>
</UserControl>
Votre Styles document "Res/Styles.xaml"
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type TextBlock}">
<Style.Setters>
<Setter Property="Foreground" Value="Blue" />
</Style.Setters>
</Style>
Votre fenêtre principale ou le parent:
<Window x:Class="WpfApplication4.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:uc="clr-namespace:WpfApplication4"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Res/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<uc:test></uc:test>
</Grid>
TextBlock dans le "test" de contrôle personnalisé affiche maintenant avec un premier plan bleu.
Yup; sauf que cela ne fonctionne pas dans Silverlight. Mais c'est cool. Je l'ai résolu en enveloppant la propriété dans un autre. Merci! –