Set default style for a type in code-behind
Asked Answered
R

1

8

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.

Rubiaceous answered 3/9, 2009 at 17:23 Comment(0)
T
11
   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);
Thoughtless answered 3/9, 2009 at 20:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.