2

I want to make my MenuFlyout to don't disappear after I click at the ToggleMenuFlyoutItem. So if you could answer how can I do it simply that would be great. I come up with an idea to make function that will be called when any of ToggleMenuFlyoutItem has been clicked where I don;t hide MenuFlyout. Here's XAML code snippet of my Hub:

<Hub x:Uid="SettingsPageTitle" x:Name="settingsPage" Header="Settings">
        <HubSection x:Uid="SettingsPageGeneral" x:Name="settingsGeneral" Header="General">
            <DataTemplate x:Uid="anotherSettingGeneralPage">
                <Grid>
                    <StackPanel Width="500" Height="500" x:Name="settingsGeneralPage" Background="WhiteSmoke">
                        <StackPanel x:Name="enabledDaysPage" Height="Auto">
                            <Button x:Name="enabledDays" Content="Enabled Days" FontWeight="Bold" Background="Transparent" Width="500" HorizontalContentAlignment="Left" Click="enabledDays_Click">
                                <FlyoutBase.AttachedFlyout>
                                    <MenuFlyout x:Name="enabledDaysMenuFlyout">
                                        <ToggleMenuFlyoutItem x:Name="mon" Text="Monday" Tag="enabledDay" Click="enabledDays_Click"/>
                                        <ToggleMenuFlyoutItem Text="Tuesday" x:Name="tue" Tag="enabledDay" Click="enabledDays_Click"/>
                                        <ToggleMenuFlyoutItem Text="Wednesday" x:Name="wed" Tag="enabledDay" Click="enabledDays_Click"/>
                                        <ToggleMenuFlyoutItem Text="Thursday" x:Name="thu" Tag="enabledDay" Click="enabledDays_Click"/>
                                        <ToggleMenuFlyoutItem Text="Friday" x:Name="fri" Tag="enabledDay" Click="enabledDays_Click"/>
                                        <ToggleMenuFlyoutItem Text="Saturday" x:Name="sat" Tag="enabledDay" Click="enabledDays_Click"/>
                                        <ToggleMenuFlyoutItem Text="Sunday" x:Name="sun" Tag="enabledDay" Click="enabledDays_Click"/>
                                    </MenuFlyout>
                                </FlyoutBase.AttachedFlyout>
                            </Button>
                            <TextBlock x:Name="enabledDaysText"/>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </DataTemplate>
        </HubSection>

So can you help to make this to happen? Or at least how can I access my MenuFlyout, note that i tried this but it didn't helped me. Thanks!

Community
  • 1
  • 1
stroibot
  • 808
  • 1
  • 11
  • 25
  • You've defined it in your XAML as enabledDaysMenuFlyout. In your code behind file, you should be able to access it by that name. Is that not working for you? What does you code file look like (where you are trying to access it)? – Pedro Silva Mar 29 '17 at 23:53
  • I read that you cannot access anything in hub section via name – stroibot Mar 30 '17 at 05:29

1 Answers1

1

If you want to click the ToggleMenuFlyoutItem and do not want the MenuFlyout to be hided. You should be able to add the Closing event of the MenuFlyout.

In the Closing event, we can use the FlyoutBaseClosingEventArgs.Cancel property. If we set the true to it, it will prevent the flyout from closing.

For example:

private void enabledDaysMenuFlyout_Closing(FlyoutBase sender, FlyoutBaseClosingEventArgs args)
{
    args.Cancel = true;
}

Update:

<Hub x:Uid="SettingsPageTitle" x:Name="settingsPage" Header="Settings">
    <HubSection x:Uid="SettingsPageGeneral" x:Name="settingsGeneral" Header="General">
        <DataTemplate x:Uid="anotherSettingGeneralPage">
            <Grid>
                <StackPanel Width="500" Height="500" x:Name="settingsGeneralPage" Background="WhiteSmoke">
                    <StackPanel x:Name="enabledDaysPage" Height="Auto">
                        <Button x:Name="enabledDays" Content="Enabled Days" FontWeight="Bold" Background="Transparent" Width="500" HorizontalContentAlignment="Left" Click="enabledDays_Click">
                            <FlyoutBase.AttachedFlyout>
                                <MenuFlyout x:Name="enabledDaysMenuFlyout" Closing="enabledDaysMenuFlyout_Closing">
                                    <ToggleMenuFlyoutItem x:Name="mon" Text="Monday" Tag="enabledDay" Click="enabledDays_Click" />
                                    <ToggleMenuFlyoutItem Text="Tuesday" x:Name="tue" Tag="enabledDay" Click="enabledDays_Click" />
                                    <ToggleMenuFlyoutItem Text="Wednesday" x:Name="wed" Tag="enabledDay" Click="enabledDays_Click" />
                                    <ToggleMenuFlyoutItem Text="Thursday" x:Name="thu" Tag="enabledDay" Click="enabledDays_Click" />
                                    <ToggleMenuFlyoutItem Text="Friday" x:Name="fri" Tag="enabledDay" Click="enabledDays_Click" />
                                    <ToggleMenuFlyoutItem Text="Saturday" x:Name="sat" Tag="enabledDay" Click="enabledDays_Click" />
                                    <ToggleMenuFlyoutItem Text="Sunday" x:Name="sun" Tag="enabledDay" Click="enabledDays_Click" />
                                </MenuFlyout>
                            </FlyoutBase.AttachedFlyout>
                        </Button>
                        <TextBlock x:Name="enabledDaysText" />
                    </StackPanel>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </HubSection>
</Hub>
Jayden
  • 3,276
  • 1
  • 10
  • 14
  • Unfortunately there's no Closing event – stroibot Mar 30 '17 at 05:49
  • @stroibot I mean you should be able to add the `Closing` event of the `MenuFlyout` in the XAML. – Jayden Mar 30 '17 at 05:56
  • no I cannot. "The member 'Closing' is not recognized or is not accessible." – stroibot Mar 30 '17 at 06:08
  • @stroibot From the document of the [Remarks of the Closing](https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.Primitives.FlyoutBase#events_), it available starting in Windows 10, version 1607. – Jayden Mar 30 '17 at 06:42
  • Unfortunately it isn't working anyway I changed it to ListView (even if it is uglier), but still thanks! – stroibot Mar 30 '17 at 20:22
  • @stroibot If you set the Target version to Windows 10 Anniversary Edition(10.0;Build 14393) in the Properties of the project, the event can be used. – Jayden Mar 31 '17 at 01:49