2016-06-07 94 views
2

在我的按鈕的點擊事件中,我有幾個異步的方法,我希望他們在按鈕的Flyout內容顯示之前完成。無論如何都要將Flyout內容從顯示中延遲出來,還是在點擊與其關聯的按鈕時總是顯示?如何延遲Button.Flyout出現?

+0

也許你可以火從後面代碼的彈出窗口,一旦你的工作完成? – Romasz

+0

我一直在尋找,如果我可以,但還沒有找到方法。有一個隱藏函數調用,但我沒有看到顯示功能 – Lotzi11

+0

只需將彈出窗口與按鈕相關聯,否則它將自動顯示。與其他元素關聯或在資源中定義,然後從代碼'yourFlyout.ShowAt(UIElement);'調用。 – Romasz

回答

2

在您的情況下,不要將彈出窗口與按鈕相關聯,因爲它會自動顯示。相反,在資源或其他元素中定義您的彈出窗口,然後從代碼中調用它。樣品的例子可以是這樣的:

<Grid x:Name="RootGrid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <FlyoutBase.AttachedFlyout> 
     <MenuFlyout> 
      <MenuFlyoutItem Text="Edit"/> 
      <MenuFlyoutItem Text="Delete"/> 
     </MenuFlyout> 
    </FlyoutBase.AttachedFlyout> 
    <Button Content="Click" Click="Button_Click"> 
     <Button.Resources> 
      <MenuFlyout x:Key="secondFlyout"> 
       <MenuFlyoutItem Text="Edit"/> 
       <MenuFlyoutItem Text="Delete"/> 
      </MenuFlyout> 
     </Button.Resources> 
    </Button> 
</Grid> 

後面的代碼:

private async void Button_Click(object sender, RoutedEventArgs e) 
{ 
    await Task.Delay(2000); // your heavy job you want ot wait for 
    var thisButton = sender as FrameworkElement; 
    // first method 
    (thisButton.Resources["secondFlyout"] as FlyoutBase).ShowAt(thisButton); 
    // second method 
    // FlyoutBase.GetAttachedFlyout(RootGrid).ShowAt(thisButton); 
}