Results 1 to 2 of 2

Thread: Button Corner Radius XAML

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    South Africa
    Posts
    400

    Button Corner Radius XAML

    Hi All

    I'm very new to WPF and XAML, I'm building an application in VB.NET winforms and want to modernize the interface. I thought of using XAML, and read that I can add an ElementHost to my form and add in a XAML user control. I'm kind of getting the hang of editing gradients etc, the one thing I need to do is add a corner radius to my button and I cannot figure out how to do this, I have tried everything but nothing seems to work. Please can someone help me with this, or point me in the right direction. The code below is just for a button, please can someone help me with the corner radius.


    Code:
    <UserControl x:Class="UserControl1"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:POSt.Net"
                 mc:Ignorable="d" 
                 d:DesignHeight="296.954" d:DesignWidth="303.046">
        <Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="62" Margin="109,104,0,0" VerticalAlignment="Top" Width="74"/>
    
    
    </UserControl>
    Many thanks
    AJ

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Button Corner Radius XAML

    Here's a simple style that changes button corners to rounded. Just add it inside the UserControl.Resources XAML.

    Code:
    <UserControl.Resources>
    <Style x:Key="ButtonRoundedCorner" TargetType="Button">
                <Setter Property="Background" Value="Silver"/>
                <Setter Property="Foreground" Value="White" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="Button">
                            <Border CornerRadius="25" Background="{TemplateBinding Background}" BorderThickness="2">
                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center">
                                </ContentPresenter>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    </UserControl.Resources>
    In your Button's Style attribute, simple reference the resource.

    Code:
     <Button x:Name="button" Style="{StaticResource ButtonRoundedCorner}" ......>
    - kgc
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width