Search code examples
c#wpfbuttonpolygons

Load custom polygon as button image in WPF


I have made a small cross icon using a polygon as following:

  <Viewbox Margin="28,-22,-28,22">
        <Polygon
Points="300, 200 325,200 325,250 375,250 375,275 325,275 325,325 300,325 300,275 250,275 250,250 300,250 300,200" Height="513" Width="595">
            <Polygon.Fill>
                <SolidColorBrush Color="#666666" Opacity="100"/>
            </Polygon.Fill>
            <Polygon.RenderTransform>
                <RotateTransform CenterX="313" CenterY="237" Angle="45" />
            </Polygon.RenderTransform>
        </Polygon>
    </Viewbox>

Now I want this polygon to be loaded into my button. How can I do this?


Solution

  • Put that inside Button.Content:

    <Button ...>
        <Viewbox ...>
        </Viewbox>
    </Button>
    

    Don't forget to remove ViewBox.Margin (make Button big enough) or make it negative.


    enter image description here