I have a Style in WPF for a custom control. The style looks like this:
<Style x:Key="MyStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="LayoutRoot">
<Rectangle x:Name="background" Width="450" Height="450" RadiusX="3" RadiusY="3" Fill="White" />
<TextBlock Name="MyText" Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="5" FontSize="52" Text="Text"/>
<ContentPresenter x:Name="content" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="background" Property="Fill" Value="Red" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I want to remove the "MyText" TextBlock from the XAML code and create it programmatically, then add it to the Style.
//Create the TextBlock using a method I wrote myself
TextBlock MyTest = CreateTextBlock("Text", Brushes.Black, HorizontalAlignment.Left, VerticalAlignment.Bottom, 52);
//Now get the style I want to change
Style CurrentStyle = (Style)FindResource("MyStyle");
//What next?
How do I now add the TextBlock programmatically so that the Style matches what it was before?