0
点赞
收藏
分享

微信扫一扫

WPF 防止按钮Click时间多次点击响应

晚安大世界 03-12 21:30 阅读 2

假设这里有一个全局的资源

<Style TargetType="TextBlock">
    <Setter Property="FontSize" Value="40"/>
</Style>

这是时候有些控件可能需要一个样式在这个基础上加一点内容的

<Style x:Key="textBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
    <Setter Property="Foreground" Value="Yellow"/>
</Style>

        --其实这个TargetType="TextBlock"是TargetType="{x:Type TextBlock}"的简写

如果是普通有key的就basedon后面接静态资源就行了

<Style x:Key="textBlockStyle1" TargetType="TextBlock" BasedOn="{StaticResource textBlockStyle}">
    <Setter Property="Foreground" Value="Yellow"/>
</Style>

拓展:Sytle设置TargetType的作用就是方便给Setter设置属性,因为不同控件有不同的属性。要是没有用TargetType指定是哪个控件,Setter设置属性的时候需要加上控件的限定名:“TextBlock.Property="TextBlock.Foreground”。

举报

相关推荐

0 条评论