Hi all, I am just trying to set up my first Template App with the thought of porting my current one so it is more standards based.
However I got stuck on the first hurdle.
I was trying to add a new setting and was following the .md
It seems the template has moved on since this time and the help no longer results in a working setting being applied.
I just tried using the sample code direct from the .md to start with..
Hi @ThePyrobri I wrote the original document for adding more settings and will take a look. Can you tell me which framework you were using to try and add to?
Hi, yes I was using MVVM light.
It all seems mostly good until you get to modifying the code behind for settingspage
Instantiating the viewmodel and onnavigatedto etc seem to be quite different now.
To be clear ( and for reference) it's this doc with the issue: https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/pages/settings.md
The instructions are good for MVVM Basic, but not for MVVM Light. I'll add the appropriate ones now.
@ThePyrobri I've created some updated docs at https://github.com/Microsoft/WindowsTemplateStudio/blob/Issue918-AddSettingDocs/docs/pages/settings.md#light
Can you try these and if they work for you I'll update the current ones accordingly.
awesome I will try it out tomorrow.
cheers
brian
@mrlacey i was thinking about this, with Caliburn coming online, maybe we should start thinking about a "root" page then have each framework? Page is a tad long
Morning @mrlacey,
So I have tried this today and their are still some issues.
I can't follow this to the letter as the version of the settings page I have does not come with a 'OnNavigatedTo' event.
This is the page as created from a fresh 'New Project':
public sealed partial class SettingsPage : Page {
private SettingsViewModel ViewModel {
get { return DataContext as SettingsViewModel; }}
public SettingsPage() {
InitializeComponent();
ViewModel.Initialize();
}
}
So I tried adding the override event as per the docs and using the new initialize code in there but it has issues. The SettingsViewModel : IsAutoErrorReportingEnabled set method does indeed fire when the checkbox is selected/deselected but the checkbox does not remember the value when the app is reloaded, it is always unchecked.
It also has the side effect of breaking the switch for the theme.
So for example if on the first run I change the theme to Light and then restart the app it does indeed re-load with the Light theme but the switch is to the left and the label says dark so we seem to have lost initial binding.
Regards
Brian
@ThePyrobri What version of the tools/wizard did you use to generate your project?
I don't see what you have in the latest public release (1.2) nor in the dev nightly release.
I also remember the issue of the theme switch being set incorrectly as an old bug that has long since been fixed so it looks like a regression.
@crutkas will split this over multiple (framework specific) pages.
I tried creating a new app just yesterday. I have:
Wizard version: 1.2.17198.1
Template version: 1.2.17202.1
Regards
@ThePyrobri try https://github.com/Microsoft/WindowsTemplateStudio/blob/Issue918-AddSettingDocs/docs/pages/settings-mvvmlight.md
It works with the latest main and dev-nightly generated projects.
Ohh, you're using a Pivot&Tabs project type.
And yes, that does page loading differently..... Grrrr.
Haha ah that's annoying then 馃
working on it. The docs need to work for everything. :/
@ThePyrobri not how I wanted to be spending my day but I think I have a final solution for you
https://github.com/Microsoft/WindowsTemplateStudio/blob/Issue918-AddSettingDocs/docs/pages/settings-mvvmlight.md
@ThePyrobri have you had a chance to take a look at the latest version of the doc? It'd be good to hear what you think and if it works for you before committing it.
Hi @mrlacey sorry I have gone quiet, real work is a little crazy right now, I hope to have a look at this by the afternoon and will let you know.
@mrlacey So there still seems to be an issue, this time with the themeselector.
The new setting works fine and saves between loads now but the app crashes when you change the theme,
Is ElementTheme from Windows.UI.Xaml?
That is the only reference I can find for it but this is the error message:
System.InvalidCastException: Unable to cast object of type 'Windows.UI.Xaml.RoutedEventArgs' to type 'Windows.UI.Xaml.ElementTheme'.
@ThePyrobri It seems that I'd got things muddled along with changes for #350 which should go in #921
Anyway, these docs work for me with the release code.
Thanks for your assistance and patience. It really shouldn't take this long to fix what should be simple documentation. Make me anxious about all the other documentation tasks I have ahead...
@ThePyrobri assume anything in #921 holds for what the current dev branch is in.
@mrlacey Many thanks for your time and patience, great work.
good luck with the rest :)
@ThePyrobri thank you for helping and telling us how to improve! Never be afraid to report an issue or even send over a pull request. Always looking for help, we just like a quick discussion first.
forgive me if this isn't the proper place to bring this up, but I'm new to WTS and stumbled on this page while trying to figure out how to add settings to my app, and wasn't sure if I'm supposed to make a new issue, or post on SO or what...
I'm deeply confused why WTS sets up settings the way it does. The UWP docs show saving settings to an App via local storage as a simple, non-async operation:
localSettings.Values["exampleSetting"] = "Hello Windows";
But the WTS generates an async method and serializes the values to a string. I can see this being optional for complex settings you want to persist, but I just want to add a simple string and store it as-is, no serialization, no async.
am I missing something and I shouldn't be using this SaveAsync method? If that's the case where is an example of adding and retrieving a simple setting? If this is not the case, why do we need to go through such a strange route (async, ensureinitialized, etc.) just to store a simple value?
@selaromdotnet, in general, we prefer it if you start new issues to ask new questions, but as you're here.
I hope this helps explain things better.
I've also created #962 to create some proper documentation on this.
Closing as original document issue now merged to dev branch.