Is it possible to do event handling in the ViewModel?
-
I have the following code in Code-Behind section of my WPF MVVM:
public EquipmentIdentity()
{
InitializeComponent();
EquipmentIdentityViewModel eivm = new EquipmentIdentityViewModel();
DataContext = eivm;
dataPager.OnDemandLoading += dataPager_OnDemandLoading;
}private void dataPager_OnDemandLoading(object sender, Syncfusion.UI.Xaml.Controls.DataPager.OnDemandLoadingEventArgs args)
{
//some codes here
}How can I remove this event handling from Code-Behind and take it to the ViewModel? When I use dataPager.OnDemandLoading += dataPager_OnDemandLoading; in ViewModel it shows this error:
Quote:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
-
I have the following code in Code-Behind section of my WPF MVVM:
public EquipmentIdentity()
{
InitializeComponent();
EquipmentIdentityViewModel eivm = new EquipmentIdentityViewModel();
DataContext = eivm;
dataPager.OnDemandLoading += dataPager_OnDemandLoading;
}private void dataPager_OnDemandLoading(object sender, Syncfusion.UI.Xaml.Controls.DataPager.OnDemandLoadingEventArgs args)
{
//some codes here
}How can I remove this event handling from Code-Behind and take it to the ViewModel? When I use dataPager.OnDemandLoading += dataPager_OnDemandLoading; in ViewModel it shows this error:
Quote:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
View models are about "data"; not "behavior". [mvc - Should MVVM models have behaviour? - Software Engineering Stack Exchange](https://softwareengineering.stackexchange.com/questions/294377/should-mvvm-models-have-behaviour)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I