WPF-在样式中使用ControlTemplate资源 [英] WPF - Use a ControlTemplate resource within a Style

查看:601
本文介绍了WPF-在样式中使用ControlTemplate资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

有可能吗?

推荐答案

我相信这会起作用:

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

这篇关于WPF-在样式中使用ControlTemplate资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆