user3821206
user3821206

Reputation: 619

call a Flyout in code behind like xaml in a universal App

I have this Flayout when I clic on the button "btn7":

    <Button HorizontalAlignment="Stretch" Background="Transparent"  x:Name="btn7" >  
<Button.Flyout>
     <Flyout Placement="Right" x:Name="FlayoutLo" >
        <Grid VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="10" Width="250">
           <Grid.RowDefinitions>
                 <RowDefinition Height="*"/>
                 <RowDefinition Height="*"/>
                 </Grid.RowDefinitions>                                  
                     <TextBox x:Name="tt" VerticalAlignment="Bottom" Grid.Row="0" ></TextBox>
                     <Button Width="120" FontWeight="Normal" Content="Enregistrer"  Background="#393185" Foreground="white" Margin="0,20,0,0"  x:Name="SecondBtn"  Grid.Row="1"   />
            </Grid>
      </Flyout>
   </Button.Flyout>
</Button>

I have an other Button,that I want to show the same Flyout at the same placement like the button "btn7" but whith C#,I have tried this:

 private  void MenuButton_Click(object sender, RoutedEventArgs e)
        {
    FlayoutLo.ShowAt(btn7);
}

but I get nothing when I clic on "MenuButton",how can I solve this problem thanks for help

Upvotes: 0

Views: 84

Answers (1)

RicardoPons
RicardoPons

Reputation: 1353

I reproduced your issue using your code and I solved the problem with this code

if (btn7.Flyout != null)
        {
            var flyout = btn7.Flyout;
            flyout.ShowAt(btn7);
        }

I hope this would be useful for you.

Upvotes: 1

Related Questions