Custom Shaped Button : Button « Windows Presentation Foundation « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Windows Presentation Foundation » ButtonScreenshots 
Custom Shaped Button
Custom Shaped Button
      
<Window x:Class="ControlTemplates.SimpleShapedButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Shaped Button" Height="510" Width="600">
  <Window.Resources>
    <ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}" >      
        <Grid>          
          <Path Name="Border" Stroke="Red" StrokeThickness="2" Stretch="Fill">
            <Path.Fill>            
                <RadialGradientBrush RadiusX="1" RadiusY="1" GradientOrigin="0.7,0.3" >
                  <GradientStop Color="Red" Offset="0" />
                  <GradientStop Color="Blue" Offset="1" />
                </RadialGradientBrush>            
            </Path.Fill>
            <Path.Data>
              <CombinedGeometry GeometryCombineMode="Union">
                <CombinedGeometry.Geometry1>                  
                  <EllipseGeometry Center="70 20" RadiusX="50" RadiusY="25"></EllipseGeometry>
                </CombinedGeometry.Geometry1>
                <CombinedGeometry.Geometry2>
                  <RectangleGeometry Rect="100 0 150 30"></RectangleGeometry>                  
                </CombinedGeometry.Geometry2>                
              </CombinedGeometry>
            </Path.Data>
          </Path>
        <Rectangle Name="FocusCue" Visibility="Hidden" Stroke="Black" StrokeThickness="1" StrokeDashArray="1 2" SnapsToDevicePixels="True" ></Rectangle>
          <Border Margin="5,10,5,10">
            <ContentPresenter  Name="Content" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" TextBlock.Foreground="White"></ContentPresenter>
          </Border>
        </Grid>
      <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
          <Setter TargetName="Border" Property="Fill" Value="DarkRed" />
        </Trigger>                
        <Trigger Property="IsPressed" Value="True">
          <Setter TargetName="Border" Property="Fill" Value="IndianRed" />
          <Setter TargetName="Border" Property="Stroke" Value="DarkKhaki" />
        </Trigger>
        <Trigger Property="IsKeyboardFocused" Value="True">
          <Setter TargetName="FocusCue" Property="Visibility" Value="Visible"></Setter>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
          <Setter TargetName="Content" Property="TextBlock.Foreground" Value="Gray"></Setter>
          <Setter TargetName="Border" Property="Fill" Value="MistyRose"></Setter>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Window.Resources>
  <StackPanel Width="150" HorizontalAlignment="Left">
    <Button Template="{StaticResource ButtonTemplate}" Click="Clicked" Name="cmdOne">A Simple Button
    </Button>
     <Button Template="{StaticResource ButtonTemplate}" IsEnabled="False" Click="Clicked" Name="cmdFour">
      <StackPanel>
        <Label>sfsdfsf</Label>
      </StackPanel>
      
    </Button>
  </StackPanel>
</Window>

//File:Window.xaml.vb
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Shapes

Namespace ControlTemplates
  Public Partial Class SimpleShapedButton
    Inherits System.Windows.Window
    Public Sub New()
      InitializeComponent()
    End Sub
    Private Sub Clicked(sender As Object, e As RoutedEventArgs)
      MessageBox.Show("You clicked " & DirectCast(sender, Button).Name)
    End Sub
  End Class
End Namespace

   
    
    
    
    
    
  
Related examples in the same category
1.Rotated ButtonsRotated Buttons
2.Pendulum ButtonPendulum Button
3.Button.Background and DrawingBrushButton.Background and DrawingBrush
4.Button with Semi-Transparent imageButton with Semi-Transparent image
5.Set Width for ButtonSet Width for Button
6.Button HorizontalAlignmentButton HorizontalAlignment
7.Button PaddingButton Padding
8.Button MarginButton Margin
9.Button Padding and HorizontalAlignmentButton Padding and HorizontalAlignment
10.Button HorizontalAlignment: StretchButton HorizontalAlignment: Stretch
11.Set BlurBitmapEffect for ButtonSet BlurBitmapEffect for Button
12.Set Padding for ButtonSet Padding for Button
13.Set Margin for ButtonSet Margin for Button
14.Set Button Content with element valueSet Button Content with element value
15.Set Button Width,Height and Content String by using AttributesSet Button Width,Height and Content String by using Attributes
16.Use Button.Content to set the content for a ButtonUse Button.Content to set the content for a Button
17.Adding image to a ButtonAdding image to a Button
18.Button with no position and sizeButton with no position and size
19.Button with Property AttributesButton with Property Attributes
20.Button with Property ElementsButton with Property Elements
21.Button with default Xml namespaceButton with default Xml namespace
22.Button with named NamespaceButton with named Namespace
23.Button Based On StyleButton Based On Style
24.Property Trigger for ButtonProperty Trigger for Button
25.Setting FontSize for ButtonSetting FontSize for Button
26.Layout Tranform
27.Using alternate elements as the content of a ButtonUsing alternate elements as the content of a Button
28.Button's Background = ImageBrush. The resulting button has an image as its backgroundButton's Background = ImageBrush. The resulting button has an image as its background
29.A rotated ButtonA rotated Button
30.Using Button.Content to set content for ButtonUsing Button.Content to set content for Button
31.Scale TransformScale Transform
32.Scale Transformate a ButtonScale Transformate a Button
33.Fisheye Effect for ButtonFisheye Effect for Button
34.A button that has been skewed and rotatedA button that has been skewed and rotated
35.Button PreviewMouseDown action and MouseDown actionButton PreviewMouseDown action and MouseDown action
36.Button click actionButton click action
37.Add CommandTarget for ButtonAdd CommandTarget for Button
38.Adding graphics to a ButtonAdding graphics to a Button
39.Button with image and text, use grid to layout Button contentButton with image and text, use grid to layout Button content
40.Canvas with Button onCanvas with Button on
41.Resizing ButtonsResizing Buttons
42.To add a button control and a text block to the canvasTo add a button control and a text block to the canvas
43.Resizing ButtonsResizing Buttons
44.To add a button control and a text block to the canvasTo add a button control and a text block to the canvas
45.A simple template for a round buttonA simple template for a round button
46.Load style defined in Xaml and apply to the ButtonLoad style defined in Xaml and apply to the Button
47.Nested Button contentNested Button content
48.Two repeat buttons that increase and decrease a numerical value.Two repeat buttons that increase and decrease a numerical value.
49.Generate Click Events Repeatedly While a Button Is ClickedGenerate Click Events Repeatedly While a Button Is Clicked
50.Button Click event handlerButton Click event handler
51.Button mouse down eventButton mouse down event
52.Button mouse down previewButton mouse down preview
53.Set button properties with Linq styleSet button properties with Linq style
54.Simple Custom ButtonSimple Custom Button
55.Raise exception from button click eventRaise exception from button click event
56.Button VerticalAlignment=Top HorizontalAlignment=LeftButton VerticalAlignment=Top  HorizontalAlignment=Left
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.