简体   繁体   中英

Why do I not have access to App.xaml.cs from other classes in my app?

I'm trying to declare a global var in App.xaml.cs this way:

sealed partial class App : Application
{
    public static string SessionKey { get; set; }
    . . .

I added a "Loaded" event to the map in MainPage.xaml.cs:

    <bm:Map x:Name="galaxyMap" Credentials="ImpeccableOrPerhapsALittleBitPeccable" 
Margin="0,0,0,0" MapType="Birdseye" Loaded="galaxyMap_OnLoaded" >

...which event gets the Session Key, assigning it to the global var:

async private void galaxyMap_OnLoaded(object sender, RoutedEventArgs args)
{
    try
    {
        App.SessionKey = await visitsMap.GetSessionIdAsync();
    }
    catch { }
}

However, when I try to access that value when making a REST call:

String httpqry = String.Format(
    "http://dev.virtualearth.net/REST/v1/Locations?addressLine={0}&locality={1}&postalCode=
{2}&adminDistrict={3}&countryRegion={4}&key={5}",
    addrElements[STREET_ADDRESS], addrElements[LOCALITY], addrElements[POSTAL_CODE], 
addrElements[ST8_PROVINCE], addrElements[COUNTRY]), 
    App.SessionKey)

...I get a red "SessionKey" and on the dot between "App" and "SessionKey" it says, " Invalid expression term '.' "

-and: " ; expected " in the same place, and " Invalid expression term ')' " on the ")" at the end of the call to String.Format().

Why is "App" unrecognized? The class where these errors occur is in the same namespace. Why wouldn't it see the application instance?

Looks like a syntax error. There is one ')' too much:

addrElements[COUNTRY])

This ')' should be removed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM