簡體   English   中英

如何在特定條件下隱藏UWP彈出

[英]How to hide UWP flyout on a specific condition

enter code here ,您好我用我UWP應用程序彈出按鈕 在按鈕上單擊我正在顯示彈出菜單中的項目列表。 當我單擊按鈕時,彈出按鈕將打開。 但是在這里我想在列表不為空時打開彈出窗口。 如果列表為空,我想隱藏彈出窗口。

為此,我編寫了代碼,但是隱藏不起作用。 任何人都可以對此有想法嗎?

XAML代碼:

 <Button TabIndex="4" Background="#212121" Name="btnCashPay" Click="btnCashPay_Tapped" HorizontalAlignment="Center" VerticalAlignment="Center" BorderBrush="#212121" BorderThickness="0" Margin="0,-5,0,0" >
<Image HorizontalAlignment="Center" VerticalAlignment="Center" Source="/Images/pay_bill(30_30).png"  Stretch="None"/>
   <Button.Flyout>
<Flyout x:Name="flyout" FlyoutPresenterStyle="{StaticResource Flyoutstyle}">

   <StackPanel>
 <TextBlock Grid.Row="0" Height="35" HorizontalAlignment="Center" Foreground="DarkTurquoise" FontWeight="SemiBold">Please Add Free Items To Cart </TextBlock>
 <Border x:Name="dgFreeItemsug" BorderThickness="0.5" Visibility="Visible" BorderBrush="LightSlateGray" Grid.Row="1" Background="White"  Height="200" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,-16,5,0">
 <ScrollViewer x:Name="svFreeItemSugg" HorizontalScrollBarVisibility="Hidden" Padding="0" VerticalScrollBarVisibility="Auto" VerticalAlignment="Top" HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="0" Margin="0,0,0,0">

 <controls:DataGrid x:Name="dgFreeItem" Height="200"  HorizontalAlignment="Stretch"  
    controls:DataGridExtensions.UseSingleSelectionAndDeselection="true" VerticalAlignment="Top"  RowBackgroundEvenBrush="White" RowBackgroundOddBrush="White" Margin="0,0,0,0" Navigate="dgFreeItem_Navigate">
     <controls:DataGrid.Columns>
 <controls:DataGridTextColumn x:Name="freeitemddesc" Width="1*" Binding="{Binding DealSku}">
 </controls:DataGridTextColumn>
  <controls:DataGridTextColumn x:Name="freeitemprice" Width="2*" Binding="{Binding DealDescription}">
  </controls:DataGridTextColumn>
  </controls:DataGrid.Columns>
 </controls:DataGrid>
 </ScrollViewer>
   </Border>
   </StackPanel>
 </Flyout>
 </Button.Flyout>
</Button>

xaml.cs代碼:

private void btnCardPay_Tapped(object sender, RoutedEventArgs e)
{
    txtcardmessage.Text = string.Empty;
    media.Play();
    if (objfreeitemlist == null)
        btnCardPay.Flyout.Hide();
}

您可以將彈出按鈕定義為按鈕資源

<Button x:Name="MyButton" Content="Button" Tapped="Button_Tapped" >
    <Button.Resources>
        <Flyout x:Name="MyFlyout">
            ....
        </Flyout>
    </Button.Resources>
</Button>

這樣,您必須自己打開“彈出”,但是可以定義何時打開它。

private void Button_Tapped(object sender, TappedRoutedEventArgs e)
{
    var button = sender as Button;

    if (button != null && objfreeitemlist != null)
    {
        MyFlyout.ShowAt(button);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM