views:

8

answers:

0

hi, i have an datagrid where i am binding it. it is a simple way what i have done.

now i need to do the same thing using mvvm Architecture

if any one can help me out how to do it. it would be great below is my code

any help would be great

<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  x:Class="SilverlightApplication2.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
      <Grid x:Name="LayoutRoot">
          <Grid.RowDefinitions>
                <RowDefinition Height="20" x:Name="HeaderRow" />
                <RowDefinition Height="*" x:Name="FooterRow"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

          <Button Click="Button_Click"></Button>
           <data:DataGrid  x:Name="dgCustomers"  Grid.Row="1" Grid.Column="1" 
                   AutoGenerateColumns="True">


                </data:DataGrid>


        </Grid>
    </UserControl>


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;
using System.Windows.Controls.Data;

using SilverlightApplication2.ServiceReference1;
namespace SilverlightApplication2
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SilverlightApplication2.ServiceReference1.DataServiceClient client = new SilverlightApplication2.ServiceReference1.DataServiceClient();
            client.GetAllEmployeesCompleted += new EventHandler<GetAllEmployeesCompletedEventArgs>(client_GetAllEmployeesCompleted);
            client.GetAllEmployeesAsync();
        }

        void client_GetAllEmployeesCompleted(object sender, GetAllEmployeesCompletedEventArgs e)
        {
            DataGrid dgCustomers = this.FindName("dgCustomers") as DataGrid;
            dgCustomers.ItemsSource = e.Result;

        }
    }
}

related questions