Set default style for code type

How to set a default style for a code type, for example. 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 tooltip in reverse code and not in xaml markup.

+6
styles wpf code-behind
source share
1 answer
  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); 
+8
source share

All Articles