(New user of xamDataGrid 8.1)
My ultimate goal is to be able to perform my logic in my viewmodel class.
I am binding the grid to an XmlDataProvider, and currently I've got it to work sort of by hooking the SelectedItemsChanging event and adding a dummy xml attribute to the bound data indicating if it is selected or not. While seems to work it feels like a hack.
Would it possible to directly bind the IsSelected of a datarecord to an xml attribute?
Is there a better way to make the viewmodel aware of currently selected items/records without taking a reference to the grid?
Hi Dominik,
We have had a lot of problems with the xamDataGrid when binding directly to an ObservableCollection. Our solution is to expose its ListCollectionView instead and bind to that.
I would be interested to know if that solves your problem!
Dayne
Hi dembrats!My Object Structure (simplified) looks as follows: public class PersonListViewModel { public ObservableCollection<Person> Persons { get; set; } public PersonListViewModel() { Persons = new ObservableCollection<Person>() { new Person(){Name = "Homer"}, new Person(){Name = "Marge"}, new Person(){Name = "Bart"}, new Person(){Name = "Lista"}, new Person(){Name = "Maggie"}, }; } } public class Person : INotifyPropertyChanged { public bool IsSelected { get; set; } public string Name { get; set; } } If I use the following XAML I get the BindingExpression Error: System.Windows.Data Error: 39 : BindingExpression path error: 'DataItem' property not found on 'object' ''PersonListViewModel' (HashCode=45523402)'. BindingExpression:Path=DataItem.IsSelected; DataItem='PersonListViewModel' (HashCode=45523402); target element is 'DataRecordPresenter' (Name=''); target property is 'IsSelected' (type 'Boolean')
XAML: <Window x:Class="WpfApplication4.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:l="clr-namespace:WpfApplication4" xmlns:igDP="http://infragistics.com/DataPresenter"> <Window.DataContext> <l:PersonListViewModel /> </Window.DataContext> <Grid> <igDP:XamDataGrid Name="xamDataGrid1" DataSource="{Binding Persons}"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:DataRecordPresenter}"> <Setter Property="IsSelected" Value="{Binding DataItem.IsSelected, Mode=TwoWay}"/> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="Name" Label="Name"/> <igDP:Field Name="IsSelected" Label="IsSelected" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid></Window>Although the IsSelected Property is set correctly by now, I have experienced a negative performance impact when loading a large list of objects. Especially when scrolling via scrollbar, there are a lot of the following Binding Errors:System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Windows.DataPresenter.DataRecordCellArea', AncestorLevel='1''. BindingExpression:Path=IsSelected; DataItem=null; target element is 'CellValuePresenter' (Name=''); target property is 'NoTarget' (type 'Object')Is there a way to avoid these binding errors?Best regards,Dominik
Got it - I forgot fireing the propertychange event in the bound object. Sorry x)
Your XamDataGrid.DataSource is bound to the Persons property. What type is that?
Hello,
I am not sure why this code snippet would not be working.
Do you have an IsSelected property of the underlying business object ?