0

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?

Picrofo Software
  • 5,475
  • 3
  • 23
  • 37
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • in SetAndSaveSectionNames shouldn't the call be hubPageSettingsFlyout.popupSectionName.IsOpen = true? – Jim O'Neil Nov 02 '12 at 23:53
  • When I replace this: TimeAndSpaceLines.View.TSLsSettings.popupSectionName.IsOpen = true; with this: hubPageSettingsFlyout.popupSectionName.IsOpen = true; ...I get, "'TimeAndSpaceLines.View.TSLsSettings.popupSectionName' is inaccessible due to its protection level" The declaration for hubPageSettingsFlyout in xaml is: So I'm still confused. I've probably got it all wrong; I'll have to take a step back and start over again. – B. Clay Shannon-B. Crow Raven Nov 03 '12 at 23:45

3 Answers3

2

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.

N_A
  • 19,799
  • 4
  • 52
  • 98
1

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;
Mayank
  • 8,777
  • 4
  • 35
  • 60
  • I believe I am doing that: private void OnSettingsPaneCommandRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) { SettingsCommand cmd = new SettingsCommand("sample", "Sound Options", (x) => { _settingsPopup = new Popup(); . . . var settingsPane = new TSLsSettings(); . . . _settingsPopup.Child = settingsPane; _settingsPopup.IsOpen = true; }); args.Request.ApplicationCommands.Add(cmd); } – B. Clay Shannon-B. Crow Raven Nov 03 '12 at 23:52
1

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

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

This will works!

JuanK
  • 2,056
  • 19
  • 32