Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WebService将Sql绑定到WP8时出现的Sql问题_C#_Web Services_Xaml_Linq To Sql_Windows Phone 8 - Fatal编程技术网

C# 使用WebService将Sql绑定到WP8时出现的Sql问题

C# 使用WebService将Sql绑定到WP8时出现的Sql问题,c#,web-services,xaml,linq-to-sql,windows-phone-8,C#,Web Services,Xaml,Linq To Sql,Windows Phone 8,我刚刚尝试创建我的第一个WP8应用程序,它将绑定SQL数据库中的数据。我遵循了教程,但只显示了黑色页面 由于WP8工具中没有列表框,我使用了LongListSelector,如下所示: MainPage.xaml shell:SystemTray.IsVisible="True"> <phone:PhoneApplicationPage.Resources> <DataTemplate x:Key="ToursDataTemplate">

我刚刚尝试创建我的第一个
WP8应用程序
,它将
绑定SQL数据库中的数据
。我遵循了教程,但只显示了
黑色页面

由于WP8工具中没有列表框,我使用了
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}"
         />   
shell:SystemTray.IsVisible=“True”>
这是我的主页.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;
        }

    }
使用PhoneApp1.Resources;
使用PhoneApp1.ToursServiceReference1;
命名空间PhoneApp1
{
公共部分类主页:PhoneApplicationPage
{
//建造师
公共主页()
{
初始化组件();
//本地化ApplicationBar的示例代码
//BuildLocalizedApplicationBar();
}
已加载专用void PhoneApplicationPage_(对象发送方,路由目标)
{
ToursServiceReference1.ToursService1Client服务客户端=新的ToursServiceReference1.ToursService1Client();
serviceClient.GetAllKlientsCompleted+=新事件处理程序(serviceClient\u GetAllKlientsCompleted);
serviceClient.GetAllKlientsAsync();
}
私有void serviceClient_GetAllKlientsCompleted(对象发送方,ToursServiceReference1.GetAllKlientsCompletedEventArgs e)
{
如果(例如,结果!=null)
{
MyLongListSelectors.ItemsSource=e.结果;
}
}
如果我需要提供更多信息,请让我知道。希望不要收到否决票,因为这是一个安静的低质量问题

没有任何错误或类似的迹象

谢谢大家抽出时间


你希望看到什么

您在
serviceClient\u GetAllKlientsCompleted
方法中没有执行任何操作。您的列表将始终为空,因为您没有向其提供任何要显示的数据

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

        }

你到底希望看到什么

您在
serviceClient\u GetAllKlientsCompleted
方法中没有执行任何操作。您的列表将始终为空,因为您没有向其提供任何要显示的数据

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

        }

我可以问一下如何将它绑定到longlistselector吗?因为我认为它可能是这样的:longlistselector.ItemsSource=e.Result;
longlistselector.DataContext=e.Result
或者甚至
ItemsSource
将起作用。这说明:非静态字段、方法、属性'System.Windows.FrameworkElement.Dat'需要对象引用aContext.get“如何解决此问题?我可以问一下如何将其绑定到longlistselector吗?因为我认为它可能是这样的:longlistselector.ItemsSource=e.Result;
longlistselector.DataContext=e.Result
甚至
ItemsSource
都会起作用。这说明:非静态字段、方法、属性需要对象引用”System.Windows.FrameworkElement.DataContext.get“如何解决此问题?”?