Evenly Spaced Dashes with StrokeDashArray

别说谁变了你拦得住时间么 提交于 2019-12-04 07:03:07
XAMeLi

I'll start from the second point.

First, the inner logic of StrokeDashArray is explained here. The important point is that the stroke dash array is not expressed in pixels, it's dependent upon stroke thickness to get the final pixel value for each number in the array.

So, for the math part, lets define some variables:

  1. S - visible portion of the stroke (same as in the link).
  2. G - the non-visible portion of the stroke (same as in the link).
  3. r - the radius of your chip. It will be half of the actual width or half of the actual height.
  4. n - the number of repetitions of S+G that you want. Integer.
  5. T - stroke thickness
  6. p - the mathematical pi (3.14...)

So we have:

2*p*r = n*(T*S+T*G)

Or,

S+G = 2pr/nT

In your case, and what I see from the image of the chip, the visible part of the stroke is square so S=1, there are six white squares with six gaps so n=6 and you decided for thickness of 30px so T=30. This gives you the value of G as:

G = 2pr/180 - 1

You can get the value of r from blend, the actual width and height will be written in parenthesis in the Width and Height boxes - divide it by two. From the details that you provided, I guess the radius is 102.55. And the final stroke dash array is:

StrokeDashArray="1,2.58"

For your first point, the answer is: it depends. If your chip is the same throughout the life-time of the application - this is the best way. It gives you the slight curvature on the outside to make the "square" flush with the outer contour of the chip and it requires a one-time calculation in design time.

Even if you have different sizes for the chip, this might be the best way to implement the graphics for the chip. Provided, you can design it with fixed size and then sticking it into a ViewBox and it still looks good.

If there's a need for variable sizes and the view box route doesn't work - there's another way to implement it (because Silverlight fails when you bind to ActualWidth\ActualHeight properties) - with Borders that hold rectangles. But it opens a whole new can of worms, and this answer is long enough. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!