简体   繁体   中英

Applying a button style to all windows that use a specific window style

I've created a Window style in Application.Resources like this:

<Style x:Key="MyWindowStyle" TargetType="Window">
  <!-- Stuff goes here -->
</Style>

I also have style rules that target all buttons:

<Style TargetType="Button">
  <!-- Stuff goes here -->
</Style>

I also have windows that don't use MyWindowStyle where I don't want to use this altered button style. Can I rewrite my button rule so that it only applies in windows that have MyWindowStyle set as their style? If you're familiar with CSS selectors, here's another way of putting it: can I use styling logic comparable to div.MyWindowStyle input[type=button] ?

You can nest the styles. Then button style will be used only within MyWindowStyle.

<Style x:Key="MyWindowStyle" TargetType="Window">
    <Style.Resources>
        <Style TargetType="Button">
            <!-- Stuff goes here -->
        </Style>
    </Style.Resources>
    <!-- Stuff goes here -->
</Style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM