Can you define multiple TargetTypes for one XAML style?

前端 未结 5 1657
被撕碎了的回忆
被撕碎了的回忆 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:54

    There is an alternative answer to the question. You CAN leave the TargetType parameter off the style altogether which will allow it to apply to various different controls, but only if you prefix the property name with "Control."

     
    

    Obviously, this only works for properties of the base control class. If you tried to set ItemsSource say, it would fail because there is no Control.ItemsSource

提交回复
热议问题