Search code examples
c#xamlbuttonflyout

Adding a button in Flyout box


I just started learning to work with Buttons and flyouts and I got to a wall Pretty early.

So this is the button I created in an .xaml:

<Button x:Name="flyout" Style="{StaticResource AppBarButtonStyle}" Tapped="OnOptionItemTapped">
<Image Source="Assets/images/icon_menu.png"/>
</Button>

and this Code is in a .cs

private void OnOptionItemTapped(object sender, TappedRoutedEventArgs e)
{
    Button button = sender as Button;
    String name = button.Name;
    if (name.Equals("flyout"))
    {
        Flyout flyout = new Flyout();
        var txt = new TextBlock();
        txt.Text = "Test";
        flyout.Content = txt;


        flyout.ShowAt(searchBtn);
    }
}

So basically I just learned how to put in text in a flyout. Next step would be a button.


Solution

  • Instead of assigning a TextBlock to the Content property of the flyout you can assign another control. For instance a Grid that contains a TextBlock and a Button.