在通用应用程序中像 xaml 一样在代码后面调用 Flyout

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

当我点击按钮时出现了这个 Flayout "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>

我有另一个按钮,我想在与按钮相同的位置显示相同的弹出窗口 "btn7" 但是使用 C#,我试过这个:

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

但是我点击"MenuButton"什么也没有,我该如何解决这个问题 感谢帮助

我用你的代码重现了你的问题,我用这段代码解决了问题

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

希望这对你有用。