Draw solid color triangle using XAML only

67,859

Solution 1

<Polygon Points="0,0 80,50, 0,100" Stroke="Black" Fill="Black" />

See API or Example.

Solution 2

I want to add these to their collection:

enter image description here

    <Polygon Points="5,0 10,10, 0,10" Stroke="Black" Fill="Black" />

enter image description here

    <Polygon Points="0,0 5,10, 10,0" Stroke="Black" Fill="Black" />

Solution 3

Using paths

<Path Width="33" Height="37" Stretch="Fill" Stroke="Black" Fill="Black" Data="F1 M 319.344,237.333L 287.328,218.849L 287.328,255.818L 319.344,237.333 Z "/>
<Path Width="33" Height="37" Stretch="Fill" Stroke="Black" Fill="Black" Data="F1 M 287.328,237.333L 319.344,255.818L 319.344,218.849L 287.328,237.333 Z "/>
Share:
67,859

Related videos on Youtube

sll
Author by

sll

Updated on September 21, 2020

Comments

  • sll
    sll over 3 years

    Is it possible to draw a filled in triangle using XAML only (not a code behind solution)?

    Triangle should be like on the image below to represent sort direction Ascending/Descending along with a sort button on a chart control:

    enter image description here

    EDIT: The solution, thanks to SpeziFish:

    Ascending:

    <Polygon Points="0,0 8,5, 0,10" Stroke="Black" Fill="Black" />
    

    Descending:

    <Polygon Points="8,0 0,5, 8,10" Stroke="Black" Fill="Black" />
    
    • erikH
      erikH over 12 years
      Drawing a triangle with an rectangle? You could look into Path instead. Look here for a basic example.
    • sll
      sll over 12 years
      @erikH : sorry, the main requirement is a XAML only
  • sll
    sll over 12 years
    sorry, the main requirement is a XAML only so Polygon is fine. How to make it smaller 10 times?
  • SpeziFish
    SpeziFish over 12 years
    Devide the numbers by ten. The numbers are easily the pixel coordinates (x,y) of the corners.
  • John Demetriou
    John Demetriou over 7 years
    how do you position and rotate though? I mean I want to draw a triangle that will be position around a circle (outside that circle) based on binding. Any ideas?
  • John Demetriou
    John Demetriou over 7 years
    how do you position and rotate though? I mean I want to draw a triangle that will be position around a circle (outside that circle) based on binding. Any ideas?
  • dba
    dba about 5 years
    for scaling you may add "Stretch=Fill", so it gets scaled to fit the parent container, e.g. Button.Content..) Ok, just spotted it in the answer of @LongZheng :)
  • dba
    dba about 5 years
    LayoutTransform could help you out. Maybe the best shot is, to create a Usercontrol with a 'Direction' Dependency Property so you could place it as often you need w/o rewriting the xaml