How to draw border with dotted line

BitSmithy 1,751 Reputation points
2020-04-15T16:48:55.817+00:00

Hello

I want to draw Border with dotted line. How to do such case?
I dont wat to use Rectangle but Border.
<Border></Border>

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Fay Wang - MSFT 5,191 Reputation points
    2020-04-20T06:38:16.193+00:00

    Hello,

    Welcome to Microsoft Q&A!

    Draw border with dotted line.

    Those which can draw dotted lines need to inherit from the Shape class, but the Border inherits from FrameworkElement. So you can't draw a Border with dotted line.

    But Rectangle for example cant carry any context.

    Rectangle can't add any child content, as a simple workaround, you can put the Rectangle and TextBlock in a Grid, let the TextBlock overlay on the Rectangle. For example:

    <Grid Width="200" Height="200">  
        <Rectangle StrokeDashArray="1.0 1.0"  
                           Stroke="Red"  
                           StrokeThickness="2"  
                           Width="200" Height="200">  
        </Rectangle>  
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">hello</TextBlock>  
    </Grid>  
    

0 additional answers

Sort by: Most helpful