Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.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-在样式中使用ControlTemplate资源_Wpf_Xaml_Styles_Controltemplate - Fatal编程技术网

WPF-在样式中使用ControlTemplate资源

WPF-在样式中使用ControlTemplate资源,wpf,xaml,styles,controltemplate,Wpf,Xaml,Styles,Controltemplate,创建样式时,是否可以将ControlTemplate属性设置为以前定义的资源?例如,如果我在ResourceDictionary中有以下内容: <ControlTemplate x:Key="MyControlTemplate" TargetType="{x:Type Button}"> ... </ControlTemplate> ... 后来想用这样的风格来使用它: <Style x:Key="MyStyle" TargetType="{x:Type Bu

创建样式时,是否可以将ControlTemplate属性设置为以前定义的资源?例如,如果我在ResourceDictionary中有以下内容:

<ControlTemplate x:Key="MyControlTemplate" TargetType="{x:Type Button}">
...
</ControlTemplate>

...
后来想用这样的风格来使用它:

<Style x:Key="MyStyle" TargetType="{x:Type Button}">
    <Setter Property="Template" Value="???"/>
</Style>


这可能吗?

我相信这会奏效:

<Style x:Key="MyStyle" TargetType="{x:Type Button}">    
    <Setter Property="Template" Value="{StaticResource MyControlTemplate}"/>
</Style>


重要的一点是,必须在创建样式之前定义模板。否则它就是XamlParseException:找不到名为/键的资源YourTemplateKey@Agent_L也可以只使用
DynamicResource