Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Is it possible to do event handling in the ViewModel?

Is it possible to do event handling in the ViewModel?

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpdesignarchitecture
2 Posts 2 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Code4Ever
    wrote on last edited by
    #1

    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.'

    L 1 Reply Last reply
    0
    • C Code4Ever

      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.'

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups