This code create an round button in wpf application using ResourceDictionary. create an xaml file like this.

<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<Style x:Key="RoundButtonTemplate" TargetType="Button">
        <Setter Property="Background" Value="Brown"/>
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border CornerRadius="15" Background="{TemplateBinding Background}"
                                BorderThickness="1">
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center">

                        </ContentPresenter>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
after that create and main window xaml file and then just call this RoundButtonTemplate style using Window.Resources load the GlassButton.xaml file and then call the StaticResource in main window like this.
<Window x:Class="GlassButton.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Glass Buttons" Height="228" Width="272">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources\GlassButton.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
<Grid>
 <StackPanel Orientation="Horizontal">
<Button Focusable="False"
        Style="{StaticResource RoundButtonTemplate}"
        Width="264"
       Height="90" 
       Grid.Row="0"
       Margin="0,0,0,0"
       HorizontalAlignment="Center"
       BorderBrush="#FFF"
       Name="PasswordButton"
       Click="PasswordButton_Click"> 
                                             
 </Button>
  </StackPanel>
</Grid>
</Window>

0 comments

Related Posts Plugin for WordPress, Blogger...