Silverlight 新手在这里,尝试做一个简单的数据绑定:
我试图获取测试数据库中所有用户的列表,但我不能;我使用 Openaccess 并遵循所有关于如何创建域模型和域服务的教程;我在执行以下代码时遇到问题,即使我在 db 上有 200 行,它也总是返回 0:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel.DomainServices.Client;
using SLTest.Web;
namespace SLTest {
public partial class MainPage : UserControl {
private TestDomainContext link = new TestDomainContext();
public MainPage() {
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
private void MainPage_Loaded(object sender, RoutedEventArgs e) {
int count = 0;
LoadOperation<DomainUser> loadOperation = link.Load(link.GetDomainUsersQuery());
loadOperation.Completed += (s, a) =>{
theList.ItemsSource = link.DomainUsers;
count = link.DomainUsers.Count();
};
}
}
}
另外,为什么那只是在做
int count = link.DomainUsers.Count();
不像在 ASP.NET 中那样工作?
这是 XAML:
<UserControl x:Class="SLTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="theGrid">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListBox Grid.Row="0" Grid.Column="0" x:Name="theList">
<DataTemplate>
<TextBlock Text="{Binding FullName}"></TextBlock>
</DataTemplate>
</ListBox>
</Grid>
</UserControl>