In my button's click event, I have a couple methods that are asynchronous that I would prefer that they finish before the button's Flyout content is displayed. Is there anyway to delay the Flyout content from display, or will it always display when the button it's associated with is clicked?
Asked
Active
Viewed 238 times
2
-
Maybe you can fire your flyout from code behind, once your work is completed? – Romasz Jun 07 '16 at 16:10
-
I've been looking to see if I can, but haven't found a way yet. There's a Hide function call, but I don't see a display function – Lotzi11 Jun 07 '16 at 16:11
-
Just don't associate the flyout with the button, otherwise it will show automatically. Associate with other element or define in resources, then invoke from code `yourFlyout.ShowAt(UIElement);`. – Romasz Jun 07 '16 at 16:33
-
Not a bad idea. I'll give it a try and let you know – Lotzi11 Jun 07 '16 at 16:39
-
I found some time to tryout the code and make it an answer. – Romasz Jun 08 '16 at 05:22
1 Answers
2
In your case do not associate flyout with button, as it will be showed automatically. Instead, define your flyout in resources or at other element, then invoke it from code. Sample example can look like this:
<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>
code behind:
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);
}

Romasz
- 29,662
- 13
- 79
- 154