Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a container where I can target the styles of a number of elements
    primarykey
    data
    text
    <p>In WPF is there container like an HTML div (where this is easy), where I could target all textblocks within that container? So I do not have to <strong>specify the style</strong> on every textblock?</p> <p>I have a complex canvas and in just a region I would like to target the textblocks.</p> <p>Something to the effect of this (where something other than StackPanel that would work as a style targeting container):</p> <pre><code> &lt;StackPanel&gt; &lt;StackPanel.Resources&gt; &lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="Foreground" Value="White"&gt;&lt;/Setter&gt; &lt;Setter Property="FontFamily" Value="Arial"&gt;&lt;/Setter&gt; &lt;/Style&gt; &lt;/StackPanel.Resources&gt; &lt;TextBlock Canvas.Left="87" Canvas.Top="210"&gt; mytext1 &lt;/TextBlock&gt; &lt;TextBlock Canvas.Left="87" Canvas.Top="232"&gt; mytext2 &lt;/TextBlock&gt; &lt;TextBlock Canvas.Left="87" Canvas.Top="254"&gt; mytext2 &lt;/TextBlock&gt; &lt;/StackPanel&gt; </code></pre> <p>So if I try a grid the canvas coordinates get ignored and my textblock appears at the top of the canvas.</p> <pre><code>&lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"&gt; &lt;Canvas Width="500" Height="500"&gt; &lt;Grid&gt; &lt;Grid.Resources&gt; &lt;Style TargetType="TextBlock"&gt; &lt;Setter Property="Foreground" Value="Red"&gt;&lt;/Setter&gt; &lt;/Style&gt; &lt;/Grid.Resources&gt; &lt;TextBlock Text="MyTextBlock1" Canvas.Left="300" Canvas.Top="300"&gt; &lt;/TextBlock&gt; &lt;/Grid&gt; &lt;/Canvas&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    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.
    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