简体   繁体   English

为什么我无法从我的应用程序中的其他类访问App.xaml.cs?

[英]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: 我试图以这种方式在App.xaml.cs中声明一个全局变量:

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

I added a "Loaded" event to the map in MainPage.xaml.cs: 我在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: 但是,当我尝试进行REST调用时尝试访问该值时:

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 '.' ...我得到一个红色的“ SessionKey”,并在“ App”和“ SessionKey”之间的点上显示“ 无效的表达式术语'。” "

-and: " ; expected " in the same place, and " Invalid expression term ')' " on the ")" at the end of the call to String.Format(). -和:“ ;预期 ”位于同一位置,并且在对String.Format()的调用结束时使用“)”上的“ 无效表达式项')' “。

Why is "App" unrecognized? 为什么无法识别“ App”? 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]) addrElements [国家])

This ')' should be removed. 这个')'应该被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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