For the three Report Views (Plot, Space, Tenant) I've used two abstract base classes, one for the view, LedgerView
, and the other for the view model, ReportBase
. In the ReportBase, I've an abstract property selectionView
, which is bound to the ComboBox like control, and when I change selection in that control, it resets the Id
property of the ReportBase and in the setter of Id property, I call updateReportables
, that fetches data from database.
Reportables
is a property of ReportBase and it points to a private field, reserved, of the ReportBase. Entries of that Reportables/reserved are displayed in the ListBox. ReportPlotVM
, ReportSpaceVM
and ReportTenantVM
are subclasses of ReporBase and, at this moment, they just set the view for the selectionView property of ReportBase.
On the top-right corner, I've the refresh button and on click, a function, refreshReport
, of ReportBase gets called and there in the first line, I've a LINQ and it throws a null reference exception! So reserved is null although, in Output
, I see there are 4 items in the reserved:
nothing else touches the reserved
other than refreshReport and updateReportables functions.
For the views, the base LedgerView has an abstract property, viewModel
, of type
ReportBase and this viewModel property becomes the DataContext
for those views. ReportPlot
, ReportSpace
and ReportTenant
are subclasses of LedgerView and they just set the viewModel property of the the LedgerView:
In the previous version of this app, I don't have this problem because I haven't use base view, LedgerView, like this and I set DataContext for each of those view separately. Now, as I'm simplifying and updating the app, I want to use the base LedgerView for all of them since their look and functionalities are same.
Why do I get that exception?