Style="{Dynami-6ren">
gpt4 book ai didi

wpf - 如何为一个控件定义多种样式?

转载 作者:行者123 更新时间:2023-12-04 00:07:23 25 4
gpt4 key购买 nike

我正在尝试在一个按钮中设置多种样式,特别是我:

样式 (1) => Style="{StaticResource VisibleAnimation}" 样式 (2) => Style="{DynamicResource AccentedSquareButtonStyle}"
一个伪代码:

<Button Content="Invia" Style="{DynamicResource AccentedSquareButtonStyle, VisibleAnimation}" ></Button>

编辑:合并的可能解决方案
<Style TargetType="FrameworkElement" x:Key="VisibleAnimation" BasedOn="{DynamicResource AccentedSquareButtonStyle}">

编译器在 BaseOn 行下划线并显示我:

Unable to set the properties for DynamicResourceExtension basedon type style. You can set DynamicResourceExtension only for a Dependency Property of a DependencyObject.



我怎么能做到这一点?

最佳答案

您可以制作 Style1 basedon Style2反之亦然,然后应用顶级 style给您的 button ,

<Window.Resources>
<Style TargetType="Button" x:Key="Style1">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
<Style TargetType="Button" x:Key="Style2" BasedOn="{StaticResource Style1}">
<Setter Property="Background" Value="Green"/>
</Style>






但是,如果您不想更改任何两种样式(例如它们在其他地方使用),请遵循此 blog post扩展您的按钮样式。

关于wpf - 如何为一个控件定义多种样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32536978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com