Definir a propriedade de estilo de um rótulo WPF no código?
No App.xaml, tenho o seguinte código:
<Application.Resources>
<Style x:Key="LabelTemplate" TargetType="{x:Type Label}">
<Setter Property="Height" Value="53" />
<Setter Property="Width" Value="130" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="99,71,0,0" />
<Setter Property="VerticalAlignment" Value= "Top" />
<Setter Property="Foreground" Value="#FFE75959" />
<Setter Property="FontFamily" Value="Calibri" />
<Setter Property="FontSize" Value="40" />
</Style>
</Application.Resources>
Isso serve para fornecer um modelo genérico para meus rótulos.
No código XAML principal, tenho a seguinte linha de código:
<Label Content="Movies" Style="{StaticResource LabelTemplate}" Name="label1" />
No entanto, gostaria de inicializar a propriedade Style através do código. Eu tentei:
label1.Style = new Style("{StaticResource LabelTemplate}");
e
label1.Style = "{StaticResource LabelTemplate}";
Nenhuma solução foi válida.
Qualquer ajuda seria apreciada :).