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

Posted on 2009-04-21
Medium Priority
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

CuteBug earned 2000 total points
ID: 24202134
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

ID: 24203537
Does this work with RepeatButton too?

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

807 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