【发布时间】:2014-11-27 18:28:16
【问题描述】:
我正在尝试以这种方式在 App.xaml.cs 中声明一个全局变量:
sealed partial class App : Application
{
public static string SessionKey { get; set; }
. . .
我在 MainPage.xaml.cs 的地图中添加了一个“Loaded”事件:
<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”之间的点上显示“Invalid expression term '.'”
-and: ";expected" 在同一个地方,和 "Invalid expression term ')'" 在调用结束时的 ")" String.Format()。
为什么“应用程序”无法识别?发生这些错误的类位于同一个命名空间中。为什么它看不到应用程序实例?
【问题讨论】:
-
需要
publiclikepublic sealed partial class App -
好主意,但不,这没有区别。此外,“App”是从 MainPage.xaml.cs 中识别出来的—— OnLoaded() 事件可以很好地看到它。
标签: c# windows-store-apps bing-maps sealed app.xaml