WPF - 在样式中使用 ControlTemplate 资源

发布于 2024-08-09 01:24:03 字数 407 浏览 1 评论 0原文

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

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

然后后来想在这样的样式中使用它:

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

这可能吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何以畏孤独 2024-08-16 01:24:03

我相信这会起作用:

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

I believe this will work:

<Style x:Key="MyStyle" TargetType="{x:Type Button}">    
    <Setter Property="Template" Value="{StaticResource MyControlTemplate}"/>
</Style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文