-
Sep 21st, 2016, 04:25 PM
#1
Thread Starter
Hyperactive Member
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
-
Sep 23rd, 2016, 03:05 AM
#2
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|