簡體   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