Can you define multiple TargetTypes for one XAML style?

前端 未结 5 1665
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 07:10

In HTML/CSS you can define a style which can be applied to many types of elements, e.g.:

.highlight {
    color:red;
}

can be applied to bo

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 07:55

    I wanted to apply a style to a Textblock and a TextBox but the selected answer didn't work for me because Textblock doesn't inherit from Control, in my case I wanted to affect the Visibility property, so I used FrameworkElement

    
    
    
    
    

    This works for the Visibility property because both items inherit from Frameworkelement and the property is defined there. Of course this will not work for properties defined only in Control, you can search the hierarchy tree and try to find a base class, anyway I thought this could help someone since this is a top search result and the selected answer is a little incomplete.

提交回复
热议问题