Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8620683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:38:18+00:00 2026-06-12T06:38:18+00:00

In a Windows 8 (WinRT) app, I am creating my own XAML style to

  • 0

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 Property="StrokeDashArray" Value="1,4". 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 Style={StaticResource myDottedStyle} I also specify the StrokeDashArray with each rectangle, then all them correctly show up with dotted borders.

Why is the dotted border only showing up for the first rectangle? How can I create a Style that is applied to all the rectangles without specifying the StrokeDashArray for each of them?

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:

<Page.Resources>
    <Style x:Key="myDottedStyle" TargetType="Rectangle">
        <Setter Property="Stroke" 
            Value="{StaticResource ApplicationForegroundThemeBrush}"/>
        <Setter Property="StrokeThickness" Value="2"/>
        <Setter Property="StrokeDashArray" Value="1,4"/>
    </Style>
</Page.Resources>

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <Rectangle Style="{StaticResource myDottedStyle}" Width="40" 
        HorizontalAlignment="Left"/>
    <Rectangle Style="{StaticResource myDottedStyle}" Width="40" 
        HorizontalAlignment="Center"/>
    <Rectangle Style="{StaticResource myDottedStyle}" Width="40" 
        HorizontalAlignment="Right"/>
</Grid>

Here is a screenshot of the output of this

I found a related question that talks about DataTemplates here but I can’t figure out how to translate that into my problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:38:20+00:00Added an answer on June 12, 2026 at 6:38 am

    You could optimize things a bit by not requiring it to re-draw the rectangle per each instance and substitute for a ContentControl instead since they appear the same but with minor differences. So something for example like;

    <Style x:Key="MyDottedStyle" TargetType="ContentControl">
        <!-- Add additional Setters Here -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ContentControl">
                    <Rectangle Stroke="{StaticResource ApplicationForegroundThemeBrush}"
                           StrokeThickness="2"
                           StrokeDashArray="1,4"
                           Width="40" Height="40"
                           HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                           Margin="{TemplateBinding Margin}"/>                                          
                </ControlTemplate>
            </Setter.Value>
        </Setter>                      
    </Style>
    
        <!-- And now actually place it on your view -->
    <ContentControl Style="{StaticResource MyDottedStyle}" HorizontalAlignment="Center"/>
    

    This will allow you to not only clean things up because you can take your Style template and slap it over into say a Resource Dictionary to reduce clutter, but also makes it a little more efficient since you’re not re-drawing your shape every time it’s required. Hope this helps! Cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WinRT Metro app (XAML/C#, Windows Release Preview) that manages documents. The
In a Metro Style app, I would like to use the WinRT provided CredentialPicker,
If you try to use Windows as part of your own namespace in Metro-style
I want to use MVVM in a WinRT (Windows 8) app, and one of
There are two WinRT applications (C#/Xaml if it matters) on Windows 8. The first
When my app is running in Windows 8 WINRT can I prevent the OS
I'm trying to create a C# WinRT component for use in metro style applications
I've looked through Generic.xaml and ThemeResources.xaml in the following path: C:\Program Files (x86)\Windows Kits\8.0\Include\WinRT\Xaml\Design
I am creating a Windows 8 app that needs to contain two main types
I'm working on a WinRT app that does login to a webpage and get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.