WPF-在样式中使用ControlTemplate资源
创建样式时,是否可以将ControlTemplate属性设置为以前定义的资源?例如,如果我在ResourceDictionary中有以下内容: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 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