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

I am try to create a button with sharp corner rather than rounded corner in WPF. Is there anyway to do it.
xewooxAsked:
Who is Participating?
 
CuteBugCommented:
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"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <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>
            </Border>
        </ControlTemplate>
    </Window.Resources>
    <Grid>
        <Button Width="100" Height="30" Template="{StaticResource ButtonTemplate}"></Button>
    </Grid>
</Window>

Open in new window

0
 
xewooxAuthor Commented:
Does this work with RepeatButton too?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.