change setter value in style

Viewed 9447

I'm programming in WPF(c#). I'm trying to change value in a setter of style.

my style is:

<Style TargetType="Control" x:Key="st">
    <Setter Property="FontFamily" Value="Tahoma"/>
    <Setter Property="FontSize" Value="14"/>
</Style>

and I use it in a button:

<Button x:Name="btnCancel" Style="{StaticResource st}" Content="انصراف" Canvas.Left="30" Canvas.Top="18" Width="139" Height="53" FontFamily="2  badr" FlowDirection="LeftToRight" Click="btnCancel_Click_1" />

and what I try to do is this code:

Style style = new Style();
style = (Style) Resources["st"];
Setter setter =(Setter) style.Setters[1];
setter.Value = 30;

after setting font size to 30 I get this error?

After a “SetterCollectionBase” is in use (sealed), it cannot be modified

How can I solve this problem?

3 Answers
Related