User Tools

Site Tools


notes:uwp:buttons

This is an old revision of the document!


Buttons in XAML

ButtonBase is the base class for all button controls.

Object
 └─DependencyObject
   └─UIElement 
     └─FrameworkElement 
       └─Control
         └─ContentControl
           └─ButtonBase
             ├─Button
             ├─HyperlinkButton
             ├─RepeatButton
             └─ToggleButton
               ├─CheckBox
               └─RadioButton

Button

Example: A simple button:

<Button Content="OK" Click="Button_Click" />

Example: A button with a Flyout:

<Button Content="Submit" Click="SubmitButton_Click">
    <Button.Flyout>
        <Flyout Placement="Top" >
            <StackPanel Background="White">
                <TextBlock>Submit</TextBlock>
                <TextBlock>More info...</TextBlock>
            </StackPanel>
        </Flyout>
    </Button.Flyout>
</Button>
private void Button_Click(object sender, RoutedEventArgs e)
{
    // ...
}

Button vs. event bubbling: PointerPressed and PointerReleased events get swallowed when they originate within a Button. If the goal is to detect taps anywhere on a Page, attach a handler to the Tapped event instead of PointerReleased.

CheckBox

<CheckBox Content="Keep alive" IsThreeState="False" Checked="CheckBox_Checked" />
private void CheckBox_Checked(object sender, RoutedEventArgs args)
{
    // ...
}

HyperlinkButton

Example: A HyperlinkButton with a Click event handler:

<HyperlinkButton Click="Button_Click">
    <TextBlock Text="Show more..." />
</HyperlinkButton>

Example: A HyperlinkButton for navigation to a web page:

<HyperlinkButton Content="Go to Wiki" NavigateUri="http://www.wbswiki.com" />
notes/uwp/buttons.1483651644.txt.gz · Last modified: 2020/08/26 (external edit)