question

BitSmithy-4663 avatar image
2 Votes"
BitSmithy-4663 asked ·

How to draw border with dotted line

Hello


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

windows-uwp
· 5
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

As far as I know, it's not possible to do it with <Border>

However, with a Rectangle, where you don't specify the Fill (thus, the Fill remains transparent), it's exactly what you want. Why do you want to avoid <Rectangle/> ?

0 Votes 0 · ·

I want to get official info, how it is about <Border>. I could not find anything valuable in net about this topic.

0 Votes 0 · ·

Those which can draw dotted lines need to inherit from the Shape class, but the Border inherits from FrameworkElement. Can you tell us why do you need to use Border to draw dotted lines?

0 Votes 0 · ·
Show more comments

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered ·

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>







· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I actually wanted to suggest something similar. I do believe he wants something else. Basically, to put the dotted line exactly around the text. But it could hypothetically do that, only after knowing the Width/height of the text.

So, we'd need to bind using ElementName. I know I've had issues in the past using ElementName in UWP, but I believe it could work

0 Votes 0 · ·