
I have developed it in silverlight 5 with mvvm architectural pattern.
in xaml
Page Code Behind
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;
namespace CheckBoxGrid
{
public partial class MainPage : UserControl
{
VM.VMSudent _studentVm = null;
public MainPage()
{
_studentVm = new VM.VMSudent();
Resources.Add("StudentSR", _studentVm);
InitializeComponent();
this.DataContext = _studentVm;
}
}
}
In Model
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace CheckBoxGrid.Model
{
public class Students:BaseClass
{
int id;
string name; public string Name
{
get { return name; }
set { name = value;
NotifyPropertyChanged("Name");
}
} public int Id
{
get { return id; }
set { id = value;
NotifyPropertyChanged("Id");
}
}
private bool isSelect; public bool IsSelect
{
get { return isSelect; }
set { isSelect = value;
NotifyPropertyChanged("IsSelect");
}
} }
}
In VMV using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CheckBoxGrid.Model;
namespace CheckBoxGrid.VMV
{
public class VMVStudent : BaseClass
{
private ObservableCollection
public ObservableCollection
{
get { return studentList; }
set
{
studentList = value;
NotifyPropertyChanged("StudentList");
}
}
private bool _IsSelectAll;
public bool IsSelectAll
{
get { return _IsSelectAll; }
set { _IsSelectAll = value;
NotifyPropertyChanged("IsSelectAll");
}
}
}
}
In VM
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using NEXTIT.ERP.LIB;
namespace CheckBoxGrid.VM
{
public class VMSudent:BaseClass
{
private VMV.VMVStudent _VMVStudent = new VMV.VMVStudent();
public VMV.VMVStudent VMVStudent
{
get { return _VMVStudent; }
set { _VMVStudent = value; }
}
public VMSudent() {
PopulateStudentList();
SelectAllCommand = new DelegateCommand(OnSelectAllCommand, CanLoadCustomers);
}
private void PopulateStudentList()
{
VMVStudent.StudentList = new System.Collections.ObjectModel.ObservableCollection
new Model.Students {Id=1,Name = "Pria"},
new Model.Students {Id=2,Name = "Smith"},
new Model.Students {Id=3,Name = "Devid"},
new Model.Students {Id=4,Name = "Helen"},
new Model.Students {Id=5,Name = "Nuton"},
new Model.Students {Id=6,Name = "Kafre"},
};
}
///
/// Loads the customers.
///
/// The parameter.
private void OnSelectAllCommand(object parameter)
{
if (((dynamic)(parameter)).IsChecked == true)
{
_VMVStudent.IsSelectAll = true;
foreach (var obj in VMVStudent.StudentList)
{
obj.IsSelect = true;
}
}
else {
_VMVStudent.IsSelectAll = false;
foreach (var obj in VMVStudent.StudentList)
{
obj.IsSelect = false;
}
}
}
public ICommand SelectAllCommand { get; set; }
///
/// Determines whether this instance [can load customers] the specified parameter.
///
/// The parameter.
///
///
/// otherwise,
///
private bool CanLoadCustomers(object parameter)
{
return true;
}
}
}
No comments:
Post a Comment