I am developing a WPF MVVM application. In it, I have a ViewModel (MainViewModel) that contains several ViewModels (ChildViewModels) corresponding to different tabs. Within these ViewModels, I need to be able to display lists and perform operations. I am not able to display data in the grids that are linked to secondary UserControls.
Main ViewModel:
public class MainViewModel : ViewModelGrid /*Implements INotifyPropertyChanged*/
{
public DocumentsViewModel DocumentsViewModel;
public ChildViewModel2 ChildViewModel2;
public MainViewModel(MainService mainService, IViewModelFactory myFactory, INotificationService notificationService)
{
DocumentsViewModel = new new DocumentsViewModel();
…
}
}
Secondary ViewModel:
public class DocumentsViewModel : ViewModelGrid /*Implements INotifyPropertyChanged*/
{
private DOCUMENT _Document;
public DOCUMENT Document
{
get{return this._Document;}
set{_Document = value;
this.RaisePropertyChanged("Document");}
}
private ObservableCollection<DOCUMENT> _Documents = new ObservableCollection<DocumentosGridPaginacion>();
public ObservableCollection<DOCUMENT> Documents
{
get{return this._Documents;}
set{_Documents = value;
this.RaisePropertyChanged("Documents");}
}
public DocumentsViewModel (DocumentsService documentsService, IViewModelFactory myFactory, INotificationService notificationService)
{
_documentsService = documentsService;
_myFactory = myFactory;
_notificationService = notificationService;
}
}
Main UserControl (MainUserControl)
<UserControl x:Class="Aplicacion.Wpf.Core.Controls">
<telerik:RadTabControl>
<telerik:RadTabItem Name="tab1" Header="Items1">
<Grid>
<Aplicacion_Controls_Documents:DocumentsViewModel></ Aplicacion_Controls_Documents:DocumentsViewModel >
</Grid>
</telerik:RadTabItem>
<telerik:RadTabItem>
…
</telerik:RadTabItem>
</telerik:RadTabControl>
</UserControl>
Secondary UserControl
<UserControl x:Class="Aplicacion.Wpf.Core.Controls.Documents.DocumentsViewModel">
<dxg:GridControl DataContext="{Binding DocumentsViewModel}" Name="dgDocuments" ItemsSource="{Binding Documents, Mode=TwoWay}" SelectedItem="{Binding Document, Mode=TwoWay}" Height="600" ShowLoadingPanel="{Binding IsBusy}">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="document_date " Header="Date" Width="100" ReadOnly="True"/>
<dxg:GridColumn FieldName="document_name" Header="Name" Width="150" ReadOnly="True" />
</dxg:GridControl.Columns>
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem Alignment="Right" />
</dxg:GridControl.TotalSummary>
</dxg:GridControl>
</UserControl>
DOCUMENT class
public class DOCUMENT
{
public long document_id { get; set; }
public string document_name { get; set; }
public DateTime document_date { get; set; }
}
I have checked the link between the MainViewModel ViewModel and its MainUserControl view is set up correctly and working. However, the issue is that even though I configure the grid’s context to use the secondary ViewModel (DocumentsViewModel), I am unable to display data in the grid. I have verified that the Documents property (within DocumentsViewModel) contains data.
I would appreciate it if someone could let me know if I’m doing something wrong or offer any advice to solve my issue. Thank you very much.
RGA is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.