WPF - Use a ControlTemplate resource within a Style

若如初见. 提交于 2019-12-04 18:42:12

问题


When creating a Style, is it possible to set the ControlTemplate property to a previously defined resource? For example, if I had the following in a ResourceDictionary:

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

And then later wanted to use it in a Style like this:

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

Is that possible?


回答1:


I believe this will work:

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


来源:https://stackoverflow.com/questions/1652420/wpf-use-a-controltemplate-resource-within-a-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!