Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default style for a type in code-behind

How to set the default style for a type in code-behind e.g. for:

<ScaleTransform x:Key="scaler" ScaleX="1.25" ScaleY="1.25" />
<Style TargetType="{x:Type ToolTip}">
  <Setter Property="LayoutTransform" Value="{DynamicResource scaler}"/>
</Style>

I need to set the style for the tooltip in code-behind instead of in the xaml markup.

like image 909
Alexander Zwitbaum Avatar asked Sep 03 '09 17:09

Alexander Zwitbaum


1 Answers

   Style style = new Style {TargetType = typeof (ToolTip)};

    Setter setter = new Setter();
    setter.Property = FrameworkElement.LayoutTransformProperty;
    setter.Value = FindResource("scaler");

    style.Setters.Add(setter);

    Resources.Add(typeof(ToolTip), style);
like image 197
Claudiu Mihaila Avatar answered Oct 16 '22 16:10

Claudiu Mihaila