繁体   English   中英

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

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

我试图以这种方式在App.xaml.cs中声明一个全局变量:

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

我在MainPage.xaml.cs中向地图添加了“已加载”事件:

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

...哪个事件获取会话密钥,并将其分配给全局变量:

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

但是,当我尝试进行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)

...我得到一个红色的“ SessionKey”,并在“ App”和“ SessionKey”之间的点上显示“ 无效的表达式术语'。”

-和:“ ;预期 ”位于同一位置,并且在对String.Format()的调用结束时使用“)”上的“ 无效表达式项')' “。

为什么无法识别“ App”? 发生这些错误的类在同一名称空间中。 为什么看不到应用程序实例?

看起来像语法错误。 ')'太多了:

addrElements [国家])

这个')'应该被删除。

暂无
暂无

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

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