I'm new to Infragistics and I therefore have a question regarding MVVM and databinding in the XamDataGrid.
What I need to know is, how I have to write the XAML for the DataGrid in order to bind properties to the columns of the grid?
I have set the DataContext of my MainWindow to an instance of a class containing a ObservableCollection with the items that I want to display. I then set the DataSource of the XamDataGrid to "{Binding Calculations}". But this apparently isn't enough...
I would also like to know how to get an instance of the selected item?
Current XAML:
<igDP:XamDataGrid Grid.Row="1" x:Name="MyGrid" DataSource="{Binding Calculations}" AssigningFieldLayoutToItem="MyGrid_AssigningFieldLayoutToItem"> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings CellClickAction="SelectRecord" AllowEdit="True" /> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout Key="master"> <igDP:Field Name="ShortName" /> <igDP:Field Name="Name" /> <igDP:Field Name="Min" /> <igDP:Field Name="Prob" /> <igDP:Field Name="Max" /> <igDP:Field Name="Mean" /> </igDP:FieldLayout> <igDP:FieldLayout Key="nested"> <igDP:Field Name="ShortName"> <igDP:Field.Settings> <igDP:FieldSettings LabelPresenterStyle="{StaticResource MyStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Name"> <igDP:Field.Settings> <igDP:FieldSettings LabelPresenterStyle="{StaticResource MyStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Min"> <igDP:Field.Settings> <igDP:FieldSettings LabelPresenterStyle="{StaticResource MyStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Prob"> <igDP:Field.Settings> <igDP:FieldSettings LabelPresenterStyle="{StaticResource MyStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Max"> <igDP:Field.Settings> <igDP:FieldSettings LabelPresenterStyle="{StaticResource MyStyle}" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="Mean"> <igDP:Field.Settings> <igDP:FieldSettings LabelPresenterStyle="{StaticResource MyStyle}" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Hi,
Let me attach a sample that using ibindinglist. It may be helpful to you. Be sure that you have implemented iNotifyPropertyChanged in your view model.
Let me know if you have any questions.
I am binding Bindilist to XAMdatagrid. so I can add new record to the XAMDatagrid. but the collection on the MVVM does not get notifiied on the property collection.
Can you please suggest me how can we achieve using MVVM.
Hi Christian,
I’m glad you were able to find a solution to your question.
We have re-focusing our efforts lately to address all outstanding posts to our forum and trying to make sure that includes any older posts. We’re gaining on the ultimate goal of not having any outstanding posts.
Please let me know if you have any further questions.
Hello Marianne
Thanks for the reply
It has ben a while since I wrote this post and I had actually forgotton about it...
I figured out the MVVM-issue from another post I found.
Thanks for the reply!
Best regards,
Christian Tang
Assuming the name of your public collection property is Calculations, the only thing I see is that your Binding statement should be DataSource="{Binding Path=Calculations}"
Be sure that you have implemented INotifyPropertyChanged for your collection class and any public properties that will need to be updated from or reflect changes in the grid.
Let me know if I can be of further assistance.