Introduced
Last Stand Windows 10 Control (Button Class)
- ButtonBase
- Button
- Hyperlinkbutton
- RepeatButton
- ToggleButton
- Appbarbutton
- Appbartogglebutton
Example
1. Examples of ButtonBase (base class)
Controls/buttoncontrol/buttonbasedemo.xaml
<page x:class= "Windows10.Controls.ButtonControl.ButtonBaseDemo" xmlns= "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.ButtonControl "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc="/HTTP/ schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0" name= "root" > <!--button-buttons control, inherited from ButtonBase, described below ButtonBase the relevant knowledge point click-clicking Event Clickmode-the mode in which the Click event is raised: Clickmode.release (default), C Lickmode.press, Clickmode.hover ispointerover-whether the device pointer (mouse or finger, etc.) is on the button ispressed-the current button is No in the pressed state Command-See bindings section CommandParameter-See Bindings section-- <button name= "Button1" content= "I am Button1" clickMode= "Release" click= "Button1_Click" margin= "5"/> <button name= "button2" content= "I am button2" clickmode= "Press" click= "Button2_Click" margin= "5"/> <button name= "Button3" content= "I am Button3" clickmode= "Hover" click= "Button3_Click" margin= "5"/> <textblock name= "LBLMSG1" margin= "5"/> <textblock Name= "LBLMSG2" margin= "5"/> </StackPanel> </Grid></Page>
Controls/buttoncontrol/buttonbasedemo.xaml.cs
/* * ButtonBase (base Class)-button control base class (inherited from ContentControl, see/controls/basecontrol/contentcontroldemo/) */using system;using Windows.ui.xaml;using windows.ui.xaml.controls;namespace windows10.controls.buttoncontrol{public sealed partial Class Buttonbasedemo:page {public Buttonbasedemo ()} {this. InitializeComponent (); This. Loaded + = buttonbasedemo_loaded; private void Buttonbasedemo_loaded (object sender, RoutedEventArgs e) {DispatcherTimer Dtimer = New DispatcherTimer (); Dtimer.interval = TimeSpan.Zero; Dtimer.tick + = Dtimer_tick; Dtimer.start (); } private void Dtimer_tick (object sender, Object e) {Lblmsg1.text = $ "Button1 ispointerover:{but Ton1. Ispointerover}, Ispressed:{button1. IsPressed} "; Lblmsg1.text + = Environment.NewLine; Lblmsg1.text + = $ "Button2 ispointerover:{button2. Ispointerover}, Ispressed:{button2. IsPressed} "; Lblmsg1.text + = Environment.NewLine; When the mouse moves to Button3, its ispointerover and ispressed are true because its clickmode is Hover lblmsg1.text + = $ "Button3 ispoint Erover:{button3. Ispointerover}, Ispressed:{button3. IsPressed} "; }//Clickmode.release-The Click event is triggered when the mouse is pressed and lifted (default value) private void Button1_Click (object sender, RoutedEventArgs E) {lblmsg2.text + = "Button1 clickmode.release"; Lblmsg2.text + = Environment.NewLine; }//Clickmode.press-The Click event is triggered by the mouse button private void button2_click (object sender, RoutedEventArgs e) {Lblmsg2.text + = "Button2 clickmode.press"; Lblmsg2.text + = Environment.NewLine; }//Clickmode.hover-The Click event is triggered by the mouse button private void Button3_Click (object sender, RoutedEventArgs e) {Lblmsg2.text + = "Button3 clickmode.hover"; Lblmsg2.text + = Environment.NewLine; } }}
2. Example of Button
Controls/buttoncontrol/buttondemo.xaml
<page x:class= "Windows10.Controls.ButtonControl.ButtonDemo" xmlns= "http://schemas.microsoft.com/winfx/2006/ Xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.ButtonControl "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc="/HTTP/ schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0" name= "root" > <!--button-buttons control Flyout-button control associated flyoutbase control-<button name= "button1" content= "Press me to eject flyout" margin= "5" > <Button.Flyout> <Flyout> <StackPanel> <TextBlock> I am the content in flyout </TextBlock> </StackPanel> </Flyout> </button.flyout> </Button> </StackPanel> </Grid></Page>
Controls/buttoncontrol/buttondemo.xaml.cs
/* * button-buttons control (inherited from ButtonBase, see/CONTROLS/BUTTONCONTROL/BUTTONBASEDEMO.XAML) */using Windows.UI.Xaml.Controls; Namespace windows10.controls.buttoncontrol{public sealed partial class Buttondemo:page { public Buttondemo () {this . InitializeComponent ();}}}
3. Examples of Hyperlinkbutton
Controls/buttoncontrol/hyperlinkbuttondemo.xaml
<page x:class= "Windows10.Controls.ButtonControl.HyperlinkButtonDemo" xmlns= "http// Schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml " xmlns:local= "Using:Windows10.Controls.ButtonControl" xmlns:d= "http://schemas.microsoft.com/expression /blend/2008 " xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 " mc:ignorable=" D " > <grid background= "Transparent" > <stackpanel margin= "0" > <!-- Hyperlinkbutton-button with hyperlink NavigateUri-button to navigate to the Uri--
Controls/buttoncontrol/hyperlinkbuttondemo.xaml.cs
/* * Hyperlinkbutton-Hyperlink button (inherited from ButtonBase, see/CONTROLS/BUTTONCONTROL/BUTTONBASEDEMO.XAML) */using Windows.ui.xaml.controls;namespace windows10.controls.buttoncontrol{public sealed partial class Hyperlinkbuttondemo:page {public Hyperlinkbuttondemo () } {this . InitializeComponent ();}}}
4. Examples of RepeatButton
Controls/buttoncontrol/repeatbuttondemo.xaml
<page x:class= "Windows10.Controls.ButtonControl.RepeatButtonDemo" xmlns= "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.ButtonControl "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc="/HTTP/ schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0" > <textblock name= "lblmsg" textwrapping= "Wrap" margin= "5"/> <!--RepeatButton-button that triggers the Click event repeatedly after holding the button Delay-the Click event is triggered first, and then this property After the specified time, the Click event starts repeatedly, in milliseconds, the default value of Interval-repeats the click event, the interval of the repetition time, in milliseconds, and the default value of 250 Note: The Button's clickmode default to Release, while RepeatButton's Clickmode defaults to press-and <repeatbutto n name= "RepeatButton" content= "hold" delay= "+" IntErval= "click=" Repeatbutton_click "margin=" 5 "/> </StackPanel> </Grid></Page>
Controls/buttoncontrol/repeatbuttondemo.xaml.cs
/* * RepeatButton-Press and hold the button that will repeatedly trigger the Click event (inherited from ButtonBase, see/CONTROLS/BUTTONCONTROL/BUTTONBASEDEMO.XAML) */using Windows . Ui. xaml;using windows.ui.xaml.controls;namespace windows10.controls.buttoncontrol{Public sealed partial class Repeatbuttondemo:page {public Repeatbuttondemo () } {this . InitializeComponent (); } private void Repeatbutton_click (object sender, RoutedEventArgs e) { Lblmsg.text + = "x";}} }
5. Examples of ToggleButton
Controls/buttoncontrol/togglebuttondemo.xaml
<page x:class= "Windows10.Controls.ButtonControl.ToggleButtonDemo" xmlns= "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.ButtonControl "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc="/HTTP/ schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0 ten" > <textblock name= "lblmsg" margin= "5"/> <!--ToggleButton-button Isthreestate-switchable state-whether 3 status is supported (default: false) IsChecked-The selected state of the button: false, True, null (the Checked event or unchecked event or indeterminate event is triggered when this property is modified) Checked- Event triggered when the button becomes selected unchecked-the event triggered when the button becomes unchecked indeterminate-the button is triggered by an indeterminate state --<togglebutton Name= "TogglEButton1 "content=" Toggle state button "margin=" 5 "isthreestate=" False "checked=" to Gglebutton1_checked "unchecked=" togglebutton1_unchecked "Indeterminat E= "Togglebutton1_indeterminate"/> <togglebutton name= "ToggleButton2" content= "switchable state button" margin= "5" Isthreestate= "True" checked= "togglebutton2_checked" Unchecked= "togglebutton2_unchecked" indeterminate= "Togglebutton2_indeterminate"/> <!--Here The result of the text box is as follows: Togglebutton3_checked togglebutton3_load Ed page_loaded--<textblock name= "LblToggleButton3" margin= "5 0 0"/> <!--for ToggleButton controls that ischecked= "True", the Checked event is triggered before it triggers the Loaded event - <togglebutton name= "ToggleButton3" content= "switchable state button" ischecked= "True" loaded= "togglebutton3_loaded" checked= " Togglebutton3_checked "margin=" 5 "/> </StackPanel> </Grid></Page>
Controls/buttoncontrol/togglebuttondemo.xaml.cs
/* * ToggleButton-switchable State button (inherited from ButtonBase, see/CONTROLS/BUTTONCONTROL/BUTTONBASEDEMO.XAML) */using system;using Windows.ui.xaml;using windows.ui.xaml.controls;namespace windows10.controls.buttoncontrol{public sealed partial Class Togglebuttondemo:page {public Togglebuttondemo ()} {this. InitializeComponent (); This. Loaded + = togglebuttondemo_loaded; } private void Togglebutton1_checked (object sender, RoutedEventArgs e) {lblmsg.text = $ "Togglebu tton1_checked, ischecked:{togglebutton1.ischecked} "; } private void Togglebutton1_unchecked (object sender, RoutedEventArgs e) {lblmsg.text = $ "Toggle button1_unchecked, ischecked:{togglebutton1.ischecked} "; }//This event will not be triggered because the value of ToggleButton1 's isthreestate is false private void Togglebutton1_indeterminate (object sen Der, RoutedEventArgs e) {lblmsg.text = $ "togglebutton1_indeterminate, ISCHECKED:{TOGGLebutton1.ischecked} "; } private void Togglebutton2_checked (object sender, RoutedEventArgs e) {lblmsg.text = $ "Togglebu tton2_checked, ischecked:{togglebutton2.ischecked} "; } private void Togglebutton2_unchecked (object sender, RoutedEventArgs e) {lblmsg.text = $ "Toggle button2_unchecked, ischecked:{togglebutton2.ischecked} "; } private void Togglebutton2_indeterminate (object sender, RoutedEventArgs e) {Lblmsg.text = $ "to Gglebutton2_indeterminate, ischecked:{togglebutton2.ischecked} "; private void Togglebuttondemo_loaded (object sender, RoutedEventArgs e) {Lbltogglebutton3.text + = "page_loaded"; Lbltogglebutton3.text + = Environment.NewLine; private void Togglebutton3_loaded (object sender, RoutedEventArgs e) {lbltogglebutton3.text + = "Togglebutton3_loaded"; Lbltogglebutton3.text + = Environment.NewLine; private void Togglebutton3_checked (object sender, RoutedEventArgs e) {Lbltogglebutton3.te XT + = "togglebutton3_checked"; Lbltogglebutton3.text + = Environment.NewLine; } }}
6. Examples of Appbarbutton
Controls/buttoncontrol/appbarbuttondemo.xaml
<page x:class= "Windows10.Controls.ButtonControl.AppBarButtonDemo" xmlns= "http://schemas.microsoft.com/winfx/ 2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.ButtonControl "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc="/HTTP/ schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0" > <!--Appbarbutton-Program Bar button control (for a scenario of this control, see:/control S/navigationcontrol/appbardemo.xaml and/controls/navigationcontrol/commandbardemo.xaml) Label-the displayed text Icon-Display icons (iconelement type, about iconelement see/CONTROLS/ICONCONTROL/ICONELEMENTDEMO.XAML) Iscompact-whether the text specified by the Label is not displayed (default value False)--<!-- directly specifies that Icon is a Symbol enumeration value, at which time the Symbolico is setN--<appbarbutton name= "AppBarButton1" icon= "accept" label= "Accept" margin= "5"/> <!--need to set Icon to a Symbolicon or Fonticon or Pathicon or Bitmapicon type, you can set this --<appbarbutton name= "AppBarButton2" label= "Find" iscompact= "True" margin= "5" > <ap pbarbutton.icon> <fonticon name= "FontIcon1" fontfamily= "Segoe UI Emoji" glyph= "& #x2713;"/> ; </AppBarButton.Icon> </AppBarButton> </StackPanel> </grid></pa Ge>
Controls/buttoncontrol/appbarbuttondemo.xaml.cs
/* * Appbarbutton-The Program Bar button control (inherited from ButtonBase, see/CONTROLS/BUTTONCONTROL/BUTTONBASEDEMO.XAML) */using Windows.ui.xaml.controls;namespace windows10.controls.buttoncontrol{public sealed partial class Appbarbuttondemo:page {public Appbarbuttondemo () } {this . InitializeComponent ();}}}
7. Examples of Appbartogglebutton
Controls/buttoncontrol/appbartogglebuttondemo.xaml
<page x:class= "Windows10.Controls.ButtonControl.AppBarToggleButtonDemo" xmlns= "http://schemas.microsoft.com/ Winfx/2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using: Windows10.Controls.ButtonControl "xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 "xmlns:mc="/HTTP/ schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <stackpanel margin= "0" > <!--Appbartogglebutton-button controls for the toggle state of the program bar (a scenario for this control See also:/controls/navigationcontrol/appbardemo.xaml and/controls/navigationcontrol/commandbardemo.xaml) Labe L-displayed text icon-icons displayed (iconelement type, about iconelement see/CONTROLS/ICONCONTROL/ICONELEMENTDEMO.XAML) Iscompact-whether the text specified by the Label is not displayed (default value False)--<!--directly refers to The Icon is a Symbol enumeration value, which is set at Symbolicon --<appbartogglebutton name= "AppBarToggleButton1" icon= "accept" label= "Accept" margin= "5"/> <!--need to set Icon to a Symbolicon or Fonticon or Pathicon or Bitmapicon type, you can set this to <appbartogglebutton name= "AppBarToggleButton2" label= "Find" iscompact= "True" margin= "5" > <AppBarToggleButton.Icon> <fonticon name= "FontIcon1" fontfamily= "Segoe UI Emoji" glyph= " x2713,/> </AppBarToggleButton.Icon> </AppBarToggleButton> </stackpane L> </Grid></Page>
Controls/buttoncontrol/appbartogglebuttondemo.xaml.cs
/* * Appbartogglebutton-button control (inherited from ToggleButton, see/CONTROLS/BUTTONCONTROL/TOGGLEBUTTONDEMO.XAML) for the program bar to toggle State */using Windows.ui.xaml.controls;namespace windows10.controls.buttoncontrol{public sealed partial class Appbartogglebuttondemo:page {public Appbartogglebuttondemo () } {this . InitializeComponent ();}}}
Control (Button Class): ButtonBase, Button, Hyperlinkbutton, RepeatButton, ToggleButton, Appbarbutton, Appbartogglebutton