Note that there are some explanatory texts on larger screens.

plurals
  1. POXAML style is applied to only the first rectangle. How to make it apply to all?
    primarykey
    data
    text
    <p>In a Windows 8 (WinRT) app, I am creating my own XAML style to get a dotted rectangle. In the setter for the style, I use <code>Property="StrokeDashArray" Value="1,4"</code>. I then create a bunch of rectangles, and then explicitly set the style of those rectangles to this style I created. The first rectangle shows up with a dotted border - but the other two don't. However, if in addition to the <code>Style={StaticResource myDottedStyle}</code> I also specify the <code>StrokeDashArray</code> with each rectangle, then all them correctly show up with dotted borders.</p> <p>Why is the dotted border only showing up for the first rectangle? How can I create a <code>Style</code> that is applied to all the rectangles without specifying the StrokeDashArray for each of them?</p> <p>Here is a full code sample. In Windows 8 RTM, create a Blank XAML app project, and replace the Grid in the MainPage.xaml with the following:</p> <pre><code>&lt;Page.Resources&gt; &lt;Style x:Key="myDottedStyle" TargetType="Rectangle"&gt; &lt;Setter Property="Stroke" Value="{StaticResource ApplicationForegroundThemeBrush}"/&gt; &lt;Setter Property="StrokeThickness" Value="2"/&gt; &lt;Setter Property="StrokeDashArray" Value="1,4"/&gt; &lt;/Style&gt; &lt;/Page.Resources&gt; &lt;Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"&gt; &lt;Rectangle Style="{StaticResource myDottedStyle}" Width="40" HorizontalAlignment="Left"/&gt; &lt;Rectangle Style="{StaticResource myDottedStyle}" Width="40" HorizontalAlignment="Center"/&gt; &lt;Rectangle Style="{StaticResource myDottedStyle}" Width="40" HorizontalAlignment="Right"/&gt; &lt;/Grid&gt; </code></pre> <p><a href="https://imgur.com/U7LtG" rel="nofollow noreferrer">Here is a screenshot of the output of this</a></p> <p>I found a related question that talks about DataTemplates <a href="https://stackoverflow.com/questions/5170367/style-within-datatemplate-is-only-being-applied-to-the-last-item-in-itemscontrol">here</a> but I can't figure out how to translate that into my problem.</p>
    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