Hello,
I'm facing some problems with CurrentRecord. I'm binding the object with CurrentRecord. I can't get the currentrecord from the code where I keep the object.
XAML
<UserControl x:Class="DevExpTest.PersonsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:model="clr-namespace:DevExpTest"
model:ObjectReference.Declaration="{model:ObjectReference window}"
Height="419" Width="537" xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">
<UserControl.Resources>
<ObjectDataProvider ObjectType="{x:Type model:PersonsViewModel}" x:Key="viewModel">
<ObjectDataProvider.ConstructorParameters>
<model:ObjectReference Key="window"/>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
</UserControl.Resources>
<Grid>
<my1:RadGridView Margin="0,10,28,43" Name="radGridView1"
xmlns:my1="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
ItemsSource="{Binding Source={StaticResource viewModel}, Path= GetData}"
CurrentRecord="{Binding Source={StaticResource viewModel}, Path= ActiveRecord}"
/>
</Grid>
</UserControl>
ViewModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.ComponentModel;
namespace DevExpTest {
public class PersonsViewModel : INotifyPropertyChanged {
private IView _iView;
private ListCollectionView _persons;
private Person _activeRecord;
public PersonsViewModel() {
loadData();
}
private void loadData(){
List<Person> p = new List<Person>();
p.Add(new Person(){ ID = 1, Name= "Michael Sync" });
p.Add(new Person(){ ID = 1, Name= "Julia" });
_persons = new ListCollectionView(p);
}
public PersonsViewModel(IView iv)
: this() {
_iView = iv;
}
public Person ActiveRecord {
get {
return _activeRecord;
}
set {
_activeRecord = value;
SendPropertyChanged("ActiveRecord");
}
}
public ListCollectionView GetData {
get {
//_persons.Filter = obj => {
// return false;
//};
return _persons;
}
}
#region Event Handlers
/// <summary>
/// This method raises the property changed event.
/// </summary>
/// <param name="propertyName">The property name which value has been changed</param>
protected void SendPropertyChanged(string propertyName) {
if (_propertyChanged != null) {
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler _propertyChanged;
public event PropertyChangedEventHandler PropertyChanged {
add {
_propertyChanged += value;
}
remove {
_propertyChanged -= value;
}
}
#endregion
}
public class Person : INotifyPropertyChanged {
private int Id;
private string name;
public string Name
{
get { return name; }
set { name = value;
SendPropertyChanged("Name");
}
}
public int ID
{
get { return Id; }
set { Id = value;
SendPropertyChanged("ID");}
}
#region Event Handlers
/// <summary>
/// This method raises the property changed event.
/// </summary>
/// <param name="propertyName">The property name which value has been changed</param>
protected void SendPropertyChanged(string propertyName) {
if (_propertyChanged != null) {
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler _propertyChanged;
public event PropertyChangedEventHandler PropertyChanged {
add {
_propertyChanged += value;
}
remove {
_propertyChanged -= value;
}
}
#endregion
}
}
Error: Put the breakpoint in setter of ActiveRecord in ViewModel. That property will never get called.
You can download the test project in the comment of this post..
http://michaelsync.net/2008/08/09/any-recommendation-for-wpf-datagrid
Note: I think that there is a wrapper for data object in your datagrid. so, I think it might be the reason why it's not working. maybe, I think I need to call DataWrapper.ActiveRecord or something...
PS: Thanks a lot for visiting my blog, Hristo!
I'm facing some problems with CurrentRecord. I'm binding the object with CurrentRecord. I can't get the currentrecord from the code where I keep the object.
XAML
<UserControl x:Class="DevExpTest.PersonsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:model="clr-namespace:DevExpTest"
model:ObjectReference.Declaration="{model:ObjectReference window}"
Height="419" Width="537" xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">
<UserControl.Resources>
<ObjectDataProvider ObjectType="{x:Type model:PersonsViewModel}" x:Key="viewModel">
<ObjectDataProvider.ConstructorParameters>
<model:ObjectReference Key="window"/>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
</UserControl.Resources>
<Grid>
<my1:RadGridView Margin="0,10,28,43" Name="radGridView1"
xmlns:my1="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
ItemsSource="{Binding Source={StaticResource viewModel}, Path= GetData}"
CurrentRecord="{Binding Source={StaticResource viewModel}, Path= ActiveRecord}"
/>
</Grid>
</UserControl>
ViewModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.ComponentModel;
namespace DevExpTest {
public class PersonsViewModel : INotifyPropertyChanged {
private IView _iView;
private ListCollectionView _persons;
private Person _activeRecord;
public PersonsViewModel() {
loadData();
}
private void loadData(){
List<Person> p = new List<Person>();
p.Add(new Person(){ ID = 1, Name= "Michael Sync" });
p.Add(new Person(){ ID = 1, Name= "Julia" });
_persons = new ListCollectionView(p);
}
public PersonsViewModel(IView iv)
: this() {
_iView = iv;
}
public Person ActiveRecord {
get {
return _activeRecord;
}
set {
_activeRecord = value;
SendPropertyChanged("ActiveRecord");
}
}
public ListCollectionView GetData {
get {
//_persons.Filter = obj => {
// return false;
//};
return _persons;
}
}
#region Event Handlers
/// <summary>
/// This method raises the property changed event.
/// </summary>
/// <param name="propertyName">The property name which value has been changed</param>
protected void SendPropertyChanged(string propertyName) {
if (_propertyChanged != null) {
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler _propertyChanged;
public event PropertyChangedEventHandler PropertyChanged {
add {
_propertyChanged += value;
}
remove {
_propertyChanged -= value;
}
}
#endregion
}
public class Person : INotifyPropertyChanged {
private int Id;
private string name;
public string Name
{
get { return name; }
set { name = value;
SendPropertyChanged("Name");
}
}
public int ID
{
get { return Id; }
set { Id = value;
SendPropertyChanged("ID");}
}
#region Event Handlers
/// <summary>
/// This method raises the property changed event.
/// </summary>
/// <param name="propertyName">The property name which value has been changed</param>
protected void SendPropertyChanged(string propertyName) {
if (_propertyChanged != null) {
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler _propertyChanged;
public event PropertyChangedEventHandler PropertyChanged {
add {
_propertyChanged += value;
}
remove {
_propertyChanged -= value;
}
}
#endregion
}
}
Error: Put the breakpoint in setter of ActiveRecord in ViewModel. That property will never get called.
You can download the test project in the comment of this post..
http://michaelsync.net/2008/08/09/any-recommendation-for-wpf-datagrid
Note: I think that there is a wrapper for data object in your datagrid. so, I think it might be the reason why it's not working. maybe, I think I need to call DataWrapper.ActiveRecord or something...
PS: Thanks a lot for visiting my blog, Hristo!