Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 为“代码隐藏”中的类型设置默认样式_Wpf_Styles_Code Behind - Fatal编程技术网

Wpf 为“代码隐藏”中的类型设置默认样式

Wpf 为“代码隐藏”中的类型设置默认样式,wpf,styles,code-behind,Wpf,Styles,Code Behind,如何设置代码隐藏类型的默认样式,例如: <ScaleTransform x:Key="scaler" ScaleX="1.25" ScaleY="1.25" /> <Style TargetType="{x:Type ToolTip}"> <Setter Property="LayoutTransform" Value="{DynamicResource scaler}"/> </Style> 我需要在代码隐藏中而不是在xaml标记中设置

如何设置代码隐藏类型的默认样式,例如:

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

我需要在代码隐藏中而不是在xaml标记中设置工具提示的样式

   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);