我刚尝试创建WP8 application
Bind data from SQL Database
。我遵循了this教程,但只有black page appears
。
由于WP8工具中没有ListBox,我使用LongListSelector
如下:
MainPage.xaml中
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="ToursDataTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="10" Text="{Binding name}"/>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<phone:LongListSelector
x:Name="MyLongListSelectors"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource ToursDataTemplate}"
/>
这是我的MainPage.xaml.cs
using PhoneApp1.Resources;
using PhoneApp1.ToursServiceReference1;
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
ToursServiceReference1.ToursService1Client serviceClient = new ToursServiceReference1.ToursService1Client();
serviceClient.GetAllKlientsCompleted += new EventHandler<ToursServiceReference1.GetAllKlientsCompletedEventArgs>(serviceClient_GetAllKlientsCompleted);
serviceClient.GetAllKlientsAsync();
}
private void serviceClient_GetAllKlientsCompleted(object sender, ToursServiceReference1.GetAllKlientsCompletedEventArgs e)
{
if (e.Result != null)
{
MyLongListSelectors.ItemsSource = e.Result;
}
}
如果我需要提供更多信息,请告诉我。希望不要收到低票,因为这是一个安静的低质量问题。
没有任何错误或类似的迹象。
感谢大家的时间。
答案 0 :(得分:1)
您期望看到什么?
您在serviceClient_GetAllKlientsCompleted
方法中无所作为。您的列表将始终为空,因为您没有提供任何要显示的数据
private void serviceClient_GetAllKlientsCompleted(object sender, ToursServiceReference1.GetAllKlientsCompletedEventArgs e)
{
if (e.Result != null)
{
//set the data context of list here
}
}