Question

Based on what I could glean from Freeman's book "Metro Revealed" (which, BTW, is the best of those available so far, albeit weighing in at less than 100 pages), I'm trying to implement a settings flyout (popup).

I have this pertinent code:

The user control that has/is the popup:

<UserControl
    x:Class="TimeAndSpaceLines.View.TSLsSettings"
    . . .
    <Popup x:Name="popupSectionName" IsLightDismissEnabled="True" >
    . . .
    </Popup>
</UserControl>

The "main" page's xaml:

<common:LayoutAwarePage
    x:Name="pageRoot"
    . . .
    xmlns:settingsflyout="using:TimeAndSpaceLines.View"
    . . .
        </Grid>
        <settingsflyout:TSLsSettings x:Name="hubPageSettingsFlyout"/>
        <VisualStateManager.VisualStateGroups>
    . . .

The "main" page's pertinent "code-behind":

public ItemsPage()
{
    InitializeComponent();
    SettingsPane.GetForCurrentView().CommandsRequested += OnSettingsPaneCommandRequested;
}

private void OnSettingsPaneCommandRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
    // Add the commands one by one to the settings panel
    args.Request.ApplicationCommands.Add(new SettingsCommand("commandSetSection1Name",
                                                            "Change the name of Section 1", SetAndSaveSectionNames));
. . .        
}

However, when I try to open it this way:

private void SetAndSaveSectionNames(IUICommand command)
{
    TimeAndSpaceLines.View.TSLsSettings.popupSectionName.IsOpen = true;
    . . .
}

I'm greeted with:

An object reference is required for the non-static field, method, or property
'TimeAndSpaceLines.View.TSLsSettings.popupSectionName'

and:

'TimeAndSpaceLines.View.TSLsSettings.popupSectionName' is inaccessible due to its protection level

Yet popupSectionName is not a class, and the class in which it resides is public. What should I do?

Was it helpful?

Solution

Try this from "main" page's pertinent "code-behind":

var myPopUp = (PopUp)hubPageSettingsFlyout.FindName("popupSectionName");

This will works!

OTHER TIPS

TimeAndSpaceLines.View.TSLsSettings is a class name, not an instance name. What you're wanting is the name of the instance: hubPageSettingsFlyout. I would suggest using binding on your popupSectionName IsLightDismissEnabled so you don't have to try to find the UI element, but instead simply check the value of whatever property it is bound to.

it did it little different

instead of creating a UserControl, I just created a BasicPage and then from my main page created an instance of that page (see below var mypane = new CreateProvider {Height = Window.Current.Bounds.Height};) where CreateProvider is a XAML page which I pass to my Popup like _providerPopup.Child = mypane;. Try it this way, I think your UserControl will work fine too. Just assign your user control to Popup like _popup.Child = popupSectionName;.

        // Create a Popup window which will contain our flyout.
        _providerPopup = new Popup
                             {
                                 Height = Window.Current.Bounds.Height,
                                 ChildTransitions = new TransitionCollection
                                                        {
                                                            new PaneThemeTransition
                                                                {
                                                                    Edge =
                                                                        (SettingsPane.Edge ==
                                                                         SettingsEdgeLocation.Right)
                                                                            ? EdgeTransitionLocation.Right
                                                                            : EdgeTransitionLocation.Left
                                                                }
                                                        }
                             };

        // Add the proper animation for the panel.

        // Create a SettingsFlyout the same dimenssions as the Popup.
        var mypane = new CreateProvider {Height = Window.Current.Bounds.Height};

        // Place the SettingsFlyout inside our Popup window.
        _providerPopup.Child = mypane;

        // Let's define the location of our Popup.
        _providerPopup.SetValue(Canvas.LeftProperty,
                                SettingsPane.Edge == SettingsEdgeLocation.Right
                                    ? (Window.Current.Bounds.Width - SettingsWidth)
                                    : 0);
        _providerPopup.SetValue(Canvas.TopProperty, 0);
        _providerPopup.IsOpen = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top