Ustawianie właściwości Style etykiety WPF w kodzie?

W App.xaml mam następujący kod:

<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>

Ma to na celu zapewnienie ogólnego szablonu dla moich etykiet.

W głównym kodzie XAML mam następujący wiersz kodu:

<Label Content="Movies" Style="{StaticResource LabelTemplate}" Name="label1" />

Chciałbym jednak zainicjować właściwość Style za pomocą kodu. Próbowałem:

label1.Style = new Style("{StaticResource LabelTemplate}");

i

label1.Style = "{StaticResource LabelTemplate}";

Żadne rozwiązanie nie było ważne.

Każda pomoc byłaby mile widziana :).

questionAnswers(3)

yourAnswerToTheQuestion