2010-10-13 9 views
6

¿Cómo puedo tener un estilo WPF que no tiene un tipo de destino (uno que se puede aplicar a todos los objetos)?Estilo WPF sin tipo de destino?

<Style x:Key="Basic" TargetType="???"> 
    <Setter Property="FontFamily" Value="Tahoma"/> 
    <Setter Property="FontSize" Value="12"/> 
</Style> 

Quiero basar todos los demás estilos en este estilo "básico".

Regards, MadSeb

Respuesta

14

Anexar "control". al comienzo de la Propiedad y elimine TargetType. Luego, en los estilos que se derivan de él, use BasedOn con un StaticResource apuntando a la base Style.

<Style x:Key="basicStyle"> 
    <Setter Property="Control.FontFamily" Value="Tahoma" /> 
    <Setter Property="Control.FontSize" Value="12" /> 
</Style> 

<Style TargetType="{x:Type Label}" BasedOn="{StaticResource basicStyle}"> 
    <Setter Property="HorizontalAlignment" Value="Right" /> 
    <Setter Property="VerticalAlignment" Value="Center" /> 
</Style> 
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource basicStyle}"> 
    <Setter Property="HorizontalAlignment" Value="Left" /> 
    <Setter Property="VerticalAlignment" Value="Center" /> 
</Style> 
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource basicStyle}"> 
    <Setter Property="HorizontalAlignment" Value="Center" /> 
    <Setter Property="VerticalAlignment" Value="Center" /> 
    <Setter Property="Margin" Value="2,4" /> 
</Style> 
Cuestiones relacionadas