How to convert shape to Path
Last post 05-11-2008 11:24 PM by Allen Chen – MSFT. 1 replies.
Sort Posts:
05-08-2008 3:44 PM
How to convert shape to Path

I need to convert a shape to a path.

For example, a Rectangle with the height=67 and width="26"

 <Rectangle x:Name="rect1" Height="67" Width="26" Canvas.Left="40" Canvas.Top="60" Fill="Teal" Stroke="Black" StrokeThickness="5"/>  

 

Would be converted to

  <Path x:Name="_260_rectangle_animation_1_polygon2base" Stroke="black" StrokeThickness="5" Fill="teal" Visibility="Visible">
    <Path.Data>
      <RectangleGeometry Rect="0 0 26 67">
        <RectangleGeometry.Transform>
          <MatrixTransform>
            <MatrixTransform.Matrix>
              <Matrix M11="1.0" M12="0" M21="0" M22="1" OffsetX="40" OffsetY="110" />
            </MatrixTransform.Matrix>
          </MatrixTransform>
        </RectangleGeometry.Transform>
      </RectangleGeometry>
    </Path.Data>
  
  </Path>

I run into a problem when the stroke has a large thickness, such as 5. The Path is showing a bigger rectangle. I realized the path doesn't outline the stroke, it follows the center of the stroke. So it always is the nubmer of StrokeThicknes pixels bigger.  In my example, the width of the first rectangle is 26, the second  one actually is 31.

 

Does any anyone know how to make the Path behave the same as the shape?

 I know I could change the Rect to something Rect="0 0 21 67". But this is not what I am looking for.

thanks

 

 

 

 

 

 

fcb416

Joined on 04-11-2008
Posts 10
05-11-2008 11:24 PM
Marked as Answer
Re: How to convert shape to Path

Hi:

  I tested it in Expression Blend 2.5 March 2008 Preview and the rectangle is converted to:

      <Path Height="67" x:Name="rect1" Width="26" Data="M2.5,2.5 L23.5,2.5 L23.5,64.5 L2.5,64.5 z" Fill="Teal" Stretch="Fill" Stroke="Black" StrokeThickness="5" Canvas.Left="40" Canvas.Top="60"/>

  So it looks fine.

Regards

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Allen Chen – MSFT

Joined on 03-16-2007
Posts 717