Создание простого бизнес-приложения с использованием Visual Studio 2010, Silverlight 4.0 и Expression Blend
13.Теперь необходимо добавить два события элементу "DataGrid" и элементу "TextBox".
В "DataGrid" добавляем событие Loaded:
В "TextBox" событие TextChanged:
14.Откроем файл EmployeeListing.xaml.cs:
Содержание файла:
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.Windows.Navigation; 
  
 namespace SampleBusinessApplication.Views 
 { 
     public partial class EmployeeListing : Page 
     { 
         public EmployeeListing() 
         { 
             InitializeComponent(); 
         } 
  
         // Executes when the user navigates to this page. 
         protected override void OnNavigatedTo(NavigationEventArgs e) 
         { 
         } 
  
         private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
         { 
  
         } 
  
         private void empGrid_Loaded(object sender, RoutedEventArgs e) 
         { 
  
         } 
     }}15.Добавим пространство имен( namespace ) SampleBusinessApplication.Web.Services в файл EmployeeListing.xaml.cs с помощью фрагмента кода:
using SampleBusinessApplication.Web.Services
16.В событие "empGrid_Loaded" добавим строчки кода:
NwdDomainContext ctx = new NwdDomainContext();
          empGrid.ItemsSource = ctx.Employees;
          ctx.Load(ctx.GetEmployeesQuery());Где NwdDomainContext ctx = new NwdDomainContext() – объект сервиса, который мы создали ранее:
empGrid.ItemsSource = ctx.Employees – указываем источник, в нашим случае сотрудники.
ctx.Load(ctx.GetEmployeesQuery()); - загрузка данных с помощью метода сервиса GetEmployeesQuery():
Public Iqueryable<Employees> GetEmployees()
{
     return this.ObjectContext.Employees;
}17.В событие TextBox_TextChanged добавим код:
NwdDomainContext nwr = new NwdDomainContext();
            empGrid.ItemsSource = nwr.Employees;
            nwr.Load(nwr.SelectCountryEmployeeQuery(CountryTextBox.Text));В данном фрагменте кода используется метод сервиса NwdDomainService – SelectCountryEmployee():
Public Iqueryable<Employees> SelectCountryEmployee(string text)
{
     var query=from Employees in this. ObjectContext.Employees
                  where Employees.Country==text
                  select Employees;
     return query;
}18.И, в заключении, запустим Silverlight приложение в браузере:
Перейдем на страницу Employee:
Введем в текстовое поле, к примеру, значение "USA". В результате отобразится те сотрудники, которые из страны США:
 
                             





