However I noticed another problem the other day while messing around. Let's pretend your project has a setting of "Name" defined as a string with user scope. To access this setting in the main window you would use...
String Name;
Name = Properties.Settings.Default.Name;
Now try the same thing in App.xaml.vb and the compiler will complain that Settings is not valid.
The clue is buried in the error message. It's expecting a dictionary. What's happening here is that the compiler is confusing Properties.Settings with Application.Current.Properties(...) and it's expecting a dictionary key (or some dictionary reference) to follow "Properties".
To reference the settings from the App.xaml.vb you need to explicitly prefix "Properties" with the default namespace ie.
String Name;
Name = Lesson_2.Properties.Settings.Default.Name;
String Name;
Name = Lesson_2.Properties.Settings.Default.Name;
Application.Current.Properties["Name"] = Name;
Of course, Visual Basic uses the My syntax to access settings which avoids this confusion completely.
No comments:
Post a Comment