1

我刚刚尝试创建我的第WP8 application一个Bind data from SQL Database。我遵循了本教程,但仅black page appears.

由于 WP8 工具中没有 ListBox,我使用LongListSelector如下:

主页.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;
        }

    }

如果我应该提供更多信息,请告诉我。希望不要收到反对票,因为这是一个安静的低质量问题。

没有错误或类似的迹象。

谢谢大家的时间。

在此处输入图像描述

4

1 回答 1

1

你期望看到什么?

你在方法内部什么也没做serviceClient_GetAllKlientsCompleted。您的列表将始终为空,因为您没有提供任何要显示的数据

private void serviceClient_GetAllKlientsCompleted(object sender, ToursServiceReference1.GetAllKlientsCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                //set the data context of list here 
            }

        }
于 2013-08-13T13:05:42.967 回答