Comprehensive example of Button:
Front-end code:
<UserControl x: Class = "ButtonDemo. MainPage"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: d = "http://schemas.microsoft.com/expression/blend/2008"
Xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
Mc: Ignorable = "d"
D: DesignHeight = "300" d: DesignWidth = "400" Loaded = "UserControl_Loaded">
<Grid x: Name = "LayoutRoot" Background = "White">
<StackPanel Width = "400">
<Button Content = "normal Button" Grid. Column = "0"> </Button>
<Button Grid. Column = "1">
<Button. Content>
<StackPanel Orientation = "Horizontal">
<TextBlock Text = "this is the combined button" VerticalAlignment = "Center"> </TextBlock>
<Image Source = "1135203.jpg" Width =" 30 "Height =" 30 "verticalignment =" Center "> </Image>
</StackPanel>
</Button. Content>
</Button>
<Button>
<Button. Content>
<StackPanel>
<TextBlock Text = "two-part button">
</TextBlock>
<Line Stroke = "Red" StrokeThickness = "2" X1 = "0" Y1 = "10" X2 = "80" Y2 = "10"> </Line>
<TextBlock Text = "this is the lower half"> </TextBlock>
</StackPanel>
</Button. Content>
</Button>
<ToggleButton Grid. row = "1" Grid. column = "0" Height = "40" Width = "80" IsThreeState = "True" Content = "button in three states" x: name = "togBtnTest" Click = "togBtnTest_Click"> </ToggleButton>
<RepeatButton Interval = "1" Content = "continuously triggered button" x: Name = "repeatBtn" Click = "RepeatButton_Click"> </RepeatButton>
<HyperlinkButton NavigateUri = "http://www.google.com.hk" Content = "common HyperlinkButton" TargetName = "_ blank" Cursor = "Hand"/>
<StackPanel Orientation = "Vertical">
<RadioButton GroupName = "test1" VerticalAlignment = "Center">
<RadioButton. Content>
<StackPanel Orientation = "Horizontal">
<TextBlock Text = "male" verticalignment = "Top"> </TextBlock>
<Image Source = "1135203.jpg" verticalignment =" Top "Width =" 40 "Height =" 40 "> </Image>
</StackPanel>
</RadioButton. Content>
</RadioButton>
<RadioButton GroupName = "test1" VerticalAlignment = "Center">
<RadioButton. Content>
<StackPanel Orientation = "Horizontal">
<TextBlock Text = "" VerticalAlignment = "Top"> </TextBlock>
<Image Source = "1135203.jpg" verticalignment =" Top "Width =" 40 "Height =" 40 "> </Image>
</StackPanel>
</RadioButton. Content>
</RadioButton>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>
Background code:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Net;
Using System. Windows;
Using System. Windows. Controls;
Using System. Windows. Documents;
Using System. Windows. Input;
Using System. Windows. Media;
Using System. Windows. Media. Animation;
Using System. Windows. Shapes;
Namespace ButtonDemo
{
Public partial class MainPage: UserControl
{
Public MainPage ()
{
InitializeComponent ();
}
/// <Summary>
/// TogBtnTest Click Event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Private void togBtnTest_Click (object sender, RoutedEventArgs e)
{
Switch (togBtnTest. IsChecked ){
Case true:
This. togBtnTest. Content = "currently selected ";
Break;
Case false:
This. togBtnTest. Content = "not selected currently ";
Break;
Default:
This. togBtnTest. Content = "not activated currently ";
Break;
}
}
// Set the status of togBtnTest when the control is loaded.
Private void UserControl_Loaded (object sender, RoutedEventArgs e)
{
This. togBtnTest. Content = "not activated ";
}
Int clickTimes = 0;
Private void RepeatButton_Click (object sender, RoutedEventArgs e)
{
ClickTimes ++;
RepeatBtn. Content = clickTimes. ToString ();
}
}
}