我正在尝试通过制作一个提供有关 Pokemon 信息的基本应用程序来学习 Windows Phone 开发。为此,我创建了一个可移植类库 (PokeLib.dll),以便它与通用应用程序兼容。我已经通过同一解决方案(“测试”)中的项目对此进行了测试,并且效果很好。您可以查看这些代码我的Github https://github.com/Benjin/PokeLib,但据我所知,一切都很好。这两个项目位于同一个解决方案中。对于 Windows Phone 应用程序的解决方案,我将 PokeLib 添加为“现有项目”,添加了引用,并编写了几行代码以确保我可以调用它:
主页.xaml:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Name="GetDataButton" Content="GetData" Click="GetDataButton_Click" Grid.Row="0" HorizontalAlignment="Center"/>
<TextBlock Name="DataText" Text="Click to get data" Grid.Row="1" Padding="10"/>
</Grid>
MainPage.xaml.cs:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
p = new Pokemon(1); // gets data for Pokemon #1 (Bulbasaur)
}
Pokemon p;
int counter = 0;
private async void GetDataButton_Click(object sender, RoutedEventArgs e)
{
DataText.Text = "Fetching... Count: " + ++counter;
if (counter == 1) // first time button's clicked
{
await p.Create(); // populates the data container
DataText.Text = String.Format("Pokemon #{0}: {1}", p.Id, p.Name);
}
}
When I try to run this on a phone emulator, I get the following message:
. I am building the project as "debug" and have "Enable Just My Code" unchecked. I am not sure what to do under the Symbols pane, but I can add a screenshot of that too, if it'd be useful.
无论如何,应用程序打开,但当我按下 GetData 按钮时冻结。我预计它会冻结一会儿,因为该调用是同步完成的,但这是永久性的。但是,不会引发任何错误/异常。当我尝试进入 p.Create() 调用时,调试器也没有响应(可能源于屏幕截图中的消息)。
有人知道我做错了什么吗?谢谢!