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 style, and all the textblocks in SPB should use another. One way to accomplish this would be to declare the two styles in Resources, and then append Style="style1"
to all 10 textblocks in the first stack panel, and append Style="style2"
to all 10 in the second one. However, it seems like there should be some easy way to append a style to the stackpanel itself that somehow tells the stackpanel to apply it to all child elements that are textblocks. Is there anyway to do this?
The reason I naturally look for this solution is because this is exactly how you do the same sort of thing in HTML with CSS, and I was hoping there would be a similar feature to XAML with styling.
Thanks!
P.S. I am working with Silverlight, but I'm guessing my situation and whatever solution (if there is one) applies to XAML/WPF in general.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…