2

Is there a simple way to make a fully square Button? Normally, a Button is a little rounded, so how do I achieve this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Phu Minh Pham
  • 1,025
  • 7
  • 21
  • 38
  • 1
    Check it out: http://www.codeproject.com/Articles/32257/A-Style-for-Round-Glassy-WPF-Buttons. It was like first result i have found in google. :P – Piotr Auguscik Feb 23 '12 at 08:15
  • 1
    In future, if you want to know how to change some specific visual component of a control in WPF, or just wonder how it's constructed, it is useful to take a look into its structure using [Snoop](http://snoopwpf.codeplex.com/). – Samuel Slade Feb 23 '12 at 08:23
  • Stop bombing your question titles with tags, they *do not* belong there. – H.B. Feb 23 '12 at 23:37
  • Sorry I didn't know. I'm new to this. Just thought that it'll be easier when someone else is looking for this question. – Phu Minh Pham Feb 24 '12 at 12:00
  • 1
    Haha, I didn't know SO had tag police. – Brandon Moore Jan 23 '13 at 03:38

2 Answers2

5

Just create a custom button style...something like this

 <Style x:Key="ButtonStyle" TargetType="Button">
    <Setter Property="FontFamily"
            Value="Arial Narrow" />
    <Setter Property="FontSize"
            Value="13" />
    <Setter Property="Width" Value="50"/>
    <Setter Property="Height" Value="20"/>
    <Setter Property="Margin" Value="3"/>
    <Setter Property="Cursor" Value="Hand"/>
    <Setter Property="BorderBrush" Value="#FF1733D2"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="VerticalAlignment" Value="Top"/>
    <Setter Property="Foreground" Value="White"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border x:Name="Border" Background="#FF1733D2">
                    <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

If you have Blend click on the button... edit style -> edit current... and get rid of the corner radius I think

Ivan Crojach Karačić
  • 1,911
  • 2
  • 24
  • 44
4

If you mean to have width = height then see WPF dynamic layout: how to enforce square proportions (width equals height)?

If you mean to have square corners then set the CornerRadius of the Border to zero:

<ControlTemplate x:Key="SquareButton" TargetType="{x:Type Button}">  
<Border CornerRadius="0"/>  
</ControlTemplate>  

Then the button uses that template:

<Button Template="{StaticResource SquareButton}"/>
Community
  • 1
  • 1
kaj
  • 5,133
  • 2
  • 21
  • 18
  • He wants to get rid of the rounding as far as I can see – Ivan Crojach Karačić Feb 23 '12 at 08:18
  • That is correct, but still maintaining the button effect. Ivan Crojach Karačić I have used your solution but I also want to keep the button effect. Do I really have to use Blend to do that or can you do it all i XAML? – Phu Minh Pham Feb 23 '12 at 08:55
  • You just need to update the control template for your button which is why I'm only showing the relevant bit. This is just a case of editing XAML – kaj Feb 23 '12 at 09:01