2

I have a grid in the xaml which uses a resource for its attached flyout:

<Grid >
    <FlyoutBase.AttachedFlyout>
        <StaticResource ResourceKey="GridFlyout"/>
    </FlyoutBase.AttachedFlyout>

    .. other stuffs

</Grid>

and I have a defined resource in the page:

<Page.Resources>
    <MenuFlyout x:Key="GridFlyout">
        <MenuFlyoutItem Text="delete"/>
        <MenuFlyoutItem Text="like"/>
        <MenuFlyoutItem Text="edit"/>
    </MenuFlyout>

But in some conditions I want to set the following resource for the above grid:

<Page.Resources>
    <MenuFlyout x:Key="SecondaryGridFlyout">
        <MenuFlyoutItem Text="like"/>
    </MenuFlyout>

How can I do that? thanks

user3293835
  • 829
  • 2
  • 15
  • 30
  • @loop DataTemplateSelector doesn't work with Flyouts – user3293835 May 09 '14 at 12:50
  • 1
    In code, this should work: `FlyoutBase.SetAttachedFlyout(theGrid, (MenuFlyout) App.Current.Resources["SecondaryGridFlyout"]);` where `theGrid` represents the grid element you want to target with the new flyout. – WiredPrairie May 09 '14 at 14:42

1 Answers1

2

It's easiest (and fully supported) if you just do this in code. Using the attached property AttachedFlyout:

FlyoutBase.SetAttachedFlyout(theGrid, 
       (MenuFlyout) App.Current.Resources["SecondaryGridFlyout"]);

theGrid in the example above represents the Grid you want to change.

<Grid x:Name="theGrid">
    <FlyoutBase.AttachedFlyout>
        <StaticResource ResourceKey="GridFlyout"/>
    </FlyoutBase.AttachedFlyout>
    <!-- ... other stuff -->
</Grid>
WiredPrairie
  • 58,954
  • 17
  • 116
  • 143