?
Solved

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

Posted on 2009-04-21
2
Medium Priority
?
1,485 Views
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.
0
Comment
Question by:xewoox
2 Comments
 
LVL 16

Accepted Solution

by:
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"
    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
 

Author Comment

by:xewoox
ID: 24203537
Does this work with RepeatButton too?
0

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