locked
App Settings for Universal Apps

    Question

  • Hello

    I am trying to add a settings flyout to the settings pane on the windows side of a new universal app and am generally following these guidelines to do so. Unfortunately, they are written for a general Windows 8.1 app and do not completely reflect the universal app code. When I try to edit App.xaml.cs as instructed, adding:

    using Windows.UI.ApplicationSettings;

    the project wont run and gives the error "The type or namespace name 'ApplicationSettings' does not exist in the namespace "Windows.UI" (are you missing an assembly refrence?).

    Is there somewhere else that this should be added now in order to deal with the shared App.xaml code for universal apps? I'm pretty novice so any help is appreciated. If there are any example code projects that exist that have this initiated and running in a universal app, that would be great. However, I only found either universal apps that didn't have the settings flyout in the settings pane, or they were non-universal apps that did.

    I should add that I tried to move the code to the initial page to load on the windows app side of the universal app, but it didn't work.

    Thanks


    • Edited by tdemerse Friday, April 11, 2014 2:28 PM
    Friday, April 11, 2014 2:24 PM

Answers

  • Yes, it can. I believe the standard templates may do this with some of their usings, but I'm not on a rev machine so I can't check.
    • Marked as answer by tdemerse Friday, April 11, 2014 4:26 PM
    Friday, April 11, 2014 2:45 PM
    Owner

All replies

  • ApplicationSettings is for Store apps only, not for Phone apps, so you cannot use it in shared code. The best bet is probably to create methods in the target specific projects to save to ApplicationSettings or IsolatedStorage as appropriate and then call those methods from the shared code, but you could also use #ifdefs to call the right ones in the shared code.

    --Rob

    Friday, April 11, 2014 2:36 PM
    Owner
  • can the "using Windows.UI.ApplicationSettings;" namespace be added in an #ifdefs? I seem to have the notion it can't from my computer science classes, but I am not sure why I think that.
    Friday, April 11, 2014 2:40 PM
  • Yes, it can. I believe the standard templates may do this with some of their usings, but I'm not on a rev machine so I can't check.
    • Marked as answer by tdemerse Friday, April 11, 2014 4:26 PM
    Friday, April 11, 2014 2:45 PM
    Owner
  • Brilliant.

    I couldn't find the definition for windows store apps so I went with:

    // App specific namespaces initialized
    #if WINDOWS_PHONE_APP
    		//none
    #else
    		using Windows.UI.ApplicationSettings;
    #endif	
    

    This allowed me to declare the namespace no problem and the app is now running. Thanks for your extremely timely help.

    • Edited by tdemerse Friday, April 11, 2014 4:25 PM
    Friday, April 11, 2014 4:09 PM
  • Brilliant.

    I couldn't find the definition for windows store apps so I went with:

    // App specific namespaces initialized
    #if WINDOWS_PHONE_APP
    		//none
    #else
    		using Windows.UI.ApplicationSettings;
    #endif	

    This allowed me to declare the namespace no problem and the app is now running. Thanks for your extremely timely help.


    If you're still reading this: How did you get the Windows Phone version to compile? Even if I move the using and the method that creates the SettingsFlyout into the #else block, the Windows Phone version still won't compile because it doesnt know the namespace Windows. UI.ApplicationSettings. The Windows 8.1 version runs finde however.

    I solved the problem by moving App.xaml out of the shard folder. With tho App.xamls it compiles fine. Any downsides to this? I didn't notice any.

    Sunday, August 31, 2014 7:11 PM
  • You can also use the ! operator with the #ifdefs, so you can do 

    #if !WINDOWS_PHONE_APP		
    using Windows.UI.ApplicationSettings;
    #endif

    Still works exactly the same, but you wouldn't have the empty block there unless you need it.

    Sunday, August 31, 2014 9:43 PM