Set style for all textblocks in a stack panel

后端 未结 4 1539
执念已碎
执念已碎 2020-12-09 01:19

Let\'s say I have two different, distinct stack panels (we\'ll call them SPA and SPB), each with 10 textblocks as child elements. All the textblocks in SPA should use one st

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 02:11

    In the resources section for your main container put your style with a x:Key attribute and a target type of TextBlock. Then in each resources section for each StackPanel you can put a style where the BasedOn attribute is set to the key of your main style (don't forget to use StaticResource binding, not just the name of the key) and then say TargetType="{x:Type TextBlock}" and end the tag. this should bring the style into the StackPanel and style all of your TextBlocks.