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. C#
  4. How to dispose Interaction.Behaviors in WPF

How to dispose Interaction.Behaviors in WPF

Scheduled Pinned Locked Moved C#
wpfquestioncsharparchitecturetutorial
3 Posts 2 Posters 0 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'm using WPF MVVM in my project. I have used Interaction.Behaviors in the root section of one of my views:

    One of the Behavior classes is:

    public class SfDataPagerBehavior_File : Behavior, IRecipient, IRecipient
    {
    public SfDataPagerBehavior_File()
    {
    WeakReferenceMessenger.Default.Register(this);
    WeakReferenceMessenger.Default.Register(this);
    }
    protected override void OnAttached()
    {
    base.OnAttached();
    .
    .
    AssociatedObject.dataPager_file.OnDemandLoading += OnOnDemandLoading;
    //Some codes
    .
    .
    }
    protected override void OnDetaching()
    {
    base.OnDetaching();
    AssociatedObject.dataPager_file.OnDemandLoading -= OnOnDemandLoading;
    }
    public async void Receive(FileFilterText message)
    {
    //Some codes
    }
    public async void Receive(UpdateDatagrid_Pdf message)
    {
    //Some codes
    }
    }

    I want to dispose all Interaction.Behaviors in the view by pressing a button. How can I do this?

    L 1 Reply Last reply
    0
    • C Code4Ever

      I'm using WPF MVVM in my project. I have used Interaction.Behaviors in the root section of one of my views:

      One of the Behavior classes is:

      public class SfDataPagerBehavior_File : Behavior, IRecipient, IRecipient
      {
      public SfDataPagerBehavior_File()
      {
      WeakReferenceMessenger.Default.Register(this);
      WeakReferenceMessenger.Default.Register(this);
      }
      protected override void OnAttached()
      {
      base.OnAttached();
      .
      .
      AssociatedObject.dataPager_file.OnDemandLoading += OnOnDemandLoading;
      //Some codes
      .
      .
      }
      protected override void OnDetaching()
      {
      base.OnDetaching();
      AssociatedObject.dataPager_file.OnDemandLoading -= OnOnDemandLoading;
      }
      public async void Receive(FileFilterText message)
      {
      //Some codes
      }
      public async void Receive(UpdateDatagrid_Pdf message)
      {
      //Some codes
      }
      }

      I want to dispose all Interaction.Behaviors in the view by pressing a button. How can I do this?

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

      That's one of the traps of MVVM: over-engineering in order to fit the app to the pattern. It presumes one is incapable of coming up with something better on their own for their app's needs.

      "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

      C 1 Reply Last reply
      0
      • L Lost User

        That's one of the traps of MVVM: over-engineering in order to fit the app to the pattern. It presumes one is incapable of coming up with something better on their own for their app's needs.

        "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

        C Offline
        C Offline
        Code4Ever
        wrote on last edited by
        #3

        Do you mean that I cannot fix this memory leaks and I have to use Code-Behind approach to have better memory control?

        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