Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Style Hierarchy?
    primarykey
    data
    text
    <p>I may have missed something obvious with WPF, but is it possible to create styles that work hierarchically with the targeted control's child controls? To better explain, think of how CSS works to style HTML. You can hierarchically target controls with CSS via selectors:</p> <pre><code>div &gt; span em { color: blue; } ul.class &gt; li ul li { display: block; margin: 0px; } </code></pre> <p>Is it possible to achieve the same thing with WPF styles? So far, I have been creating styles for every type of control, or named styles that I directly apply to a control. However, I end up with a hell of a lot more styles than I really intend, and I is nearly impossible to style control structures together as a group.</p> <p>Thanks for any insight.</p> <p>UPDATE:</p> <p>Here is an example of what I would like to be able to do. Note that only the root ListView control has a Style applied. I would like to be able to target any one of the child controls in any one of the CellTemplates without having to directly apply the style to each of those child controls. This keeps my view layout markup more decoupled and isolated from the style markup, giving me a lot more freedom to change the style without having to explicitly create a style for every single control in my entire application.</p> <pre><code>&lt;Grid&gt; &lt;ListView Style="{StaticResource ProcessableItemsListView}"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Width="10"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;Grid&gt; &lt;CheckBox Value="{Binging ...}" /&gt; &lt;/Grid&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Width="*"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;Grid&gt; &lt;TextBlock Text="{Binding ...}" /&gt; &lt;/Grid&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Width="80"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;Grid&gt; &lt;Button Command="{Binding ...}"&gt;Process&lt;/Button&gt; &lt;/Grid&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Width="120"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;Grid&gt; &lt;ProgressBar Value="{Binding ...}" /&gt; &lt;/Grid&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListBiew&gt; &lt;/Grid&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload