How to create a button where the corner is not round in WPF

Posted on 2009-04-21
Last Modified: 2013-11-12
I am try to create a button with sharp corner rather than rounded corner in WPF. Is there anyway to do it.
Question by:xewoox
    LVL 16

    Accepted Solution

    You need to modify the template of the button and set the CornerRadius property of the Border of the button to zero.

    For example,
    To create a button with black border and gray background and a sharp corner, the xaml is given below:
    <Window x:Class="WpfApplication1.Window1"
        Title="Window1" Height="300" Width="300">
            <ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}">
                <Border SnapsToDevicePixels="True" BorderBrush="Black" BorderThickness="1" CornerRadius="0" Background="Gray" TextBlock.Foreground="Black">
                    <ContentPresenter RecognizesAccessKey="True"></ContentPresenter>
            <Button Width="100" Height="30" Template="{StaticResource ButtonTemplate}"></Button>

    Open in new window


    Author Comment

    Does this work with RepeatButton too?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now