locked
XAML: Can we define style for nested elements?

    Question

  • Can we define a style that will target "all TextBlock elements inside Border elements of style XXX"?

    I have a style <Style TargetType="Border" x:Key="XXX"> and I want all TextBlocks inside Borders with style XXX to have red Foreground.

    In CSS it would look like this:

    <html>
    <head>
    <style>
        p { color: red; }
        p.XXX { color: green; }
        p.XXX span { color: blue; }
    </style>
    </head>
    <body>
        <p>red text</p>
        <p class="XXX">green text</p>
        <p class="XXX">green text <span>and blue text</span></p>
    </body>
    </html>




    Wednesday, January 28, 2015 1:20 PM

Answers

  • Hi Michael,

    I've moved this to a more topical forum for you.

    Xaml styles do not cascade like CSS does. 

    --Rob

    Wednesday, January 28, 2015 6:59 PM
    Moderator

All replies

  • Hi Michael,

    I've moved this to a more topical forum for you.

    Xaml styles do not cascade like CSS does. 

    --Rob

    Wednesday, January 28, 2015 6:59 PM
    Moderator
  • Alright, we can do without it. Thanks, Rob.

    Thursday, January 29, 2015 8:24 AM