WPF Web Based

WPF Examples

WPF

WPF Projects

WPF Project

adplus-dvertising
Button Control In WPF Web Base
Previous Home Next

The Button element represents a WPF Button control in XAML.

 <Button></Button>

The Width and Height attributes of the Button element represent the width and the height of a Button. The Content property of the Button element sets the text of a button. The x:Name attribute represents the name of the control, which is a unique identifier of a control.

<Page x:Class="WpfBrowserApplication2.Page1"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Title="Page1">
<Grid>
<Button Height="23" Margin="97,125,128,0" Name="button1" 
           VerticalAlignment="Top">Button</Button>
</Grid>
</Page>

Important Property of Button Control:

NameDescription
AllowDrop Gets or sets a value indicating whether this element can be used as the target of a drag-and-drop operation.
AreAnyTouchesCapturedGets a value that indicates whether at least one touch is captured to this element.
AreAnyTouchesCapturedWithinGets a value that indicates whether at least one touch is captured to this element or to any child elements in its visual tree.
AreAnyTouchesDirectlyOverGets a value that indicates whether at least one touch is pressed over this element.
AreAnyTouchesOverGets a value that indicates whether at least one touch is pressed over this element or any child elements in its visual tree.
CacheModeGets or sets a cached representation of the UIElement.
ClickModeGets or sets when the Click event occurs.
ClipGets or sets the geometry used to define the outline of the contents of an element.
ClipToBoundsGets or sets a value indicating whether to clip the content of this element (or content coming from the child elements of this element) to fit into the size of the containing element.
CommandGets or sets the command to invoke when this button is pressed.
CommandBindingsGets a collection of CommandBinding objects associated with this element. A CommandBinding enables command handling for this element, and declares the linkage between a command, its events, and the handlers attached by this element.
CommandParameterGets or sets the parameter to pass to the Command property.
CommandTargetGets or sets the element on which to raise the specified command.
ContentGets or sets the content of a ContentControl.
ContentStringFormatGets or sets a composite string that specifies how to format the Content property if it is displayed as a string.
ContentTemplateGets or sets the data template used to display the content of the ContentControl.
ContentTemplateSelectorGets or sets a template selector that enables an application writer to provide custom template-selection logic.
InputBindingsGets the collection of input bindings associated with this element.
InputScopeGets or sets the context for input used by this FrameworkElement.
Adding a Button Click Event Handler

The Click attribute of the Button element adds the click event handler. The following code adds the click event handler for a Button.

<Button x:Name="Random Number" Click="RandomNumber_Click">
</Button>

Code for Web.xaml:

<Page x:Class="WpfBrowserApplication2.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1">
<Grid>
<Button Height="23" Margin="97,125,128,0" Name="button1"
 VerticalAlignment="Top" Click="button1_Click">Click me</Button>
</Grid>
</Page>

Code For Button Click Event:

namespace WpfBrowserApplication2
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Please Dont Click Me Again");
}
}
}
Output:
Previous Home Next
WPF Examples

WPF

WPF

WPF

WPF

WPF

WPF

WPF

WPF