0

name 'App' does not exist in the current context.

How that possible? Have to note my initialization code is different than MainPage() type, as I converted SketchFlow app into production Silverlight. They instruct you to do init code via System.Windows.Controls.Frame():

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new System.Windows.Controls.Frame() { Source = new Uri("/MyAppScreen.xaml", UriKind.Relative) };

}
public static string ValueFromHome =
"A Value on Home page"; 

the goal was to set up public var inside App object so I can access it from various screens down the road


Accessing Resource data requires calling App object I believe as in below, is that correct? so this won't help me

string color = App.Current.Resources["customColor"].ToString(); 
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104

1 Answers1

0

If you are just storing strings, look into using Resource files. Then they can be translated if that ever becomes necessary. EDIT (to explain the resource file usage): To access the resource, first create a .resx file in your project (let's say you name it MainResource.resx), change the access modifier drop down to public, add your string with Name: ValueFromHome and Value: "A Value on Home page". Then you can get the value by adding a using to the namespace of the resource if needed and calling it directly like so:

string value = MainResource.ValueFromHome;

I'd be wary of static variables hanging around. Maybe you could use a MainViewModel to store that value. If you really need a static variable create a new static class in your project and put your ValueFromHome property in that class. The App probably isn't available since it is a Silverlight construct and not made to be available to all areas.

AlignedDev
  • 8,102
  • 9
  • 56
  • 91
  • No, not storing static data, I need to assign values and retrieve later. So why do I get the App() object error, any idea? – user1001895 Oct 19 '11 at 05:09
  • is this a build or a runtime error? Do you have an app.xaml.cs in your project? It's hard to tell from your description. A few lines of code would probably help. – AlignedDev Oct 19 '11 at 13:18
  • Well the codestring color = App.Current.Resources["customColor"].ToString(); – user1001895 Oct 19 '11 at 20:58