ここで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>