Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:33:10+00:00 2026-06-09T14:33:10+00:00

I use MVVM pattern in my WPF application. I’m trying to cache my windows

  • 0

I use MVVM pattern in my WPF application. I’m trying to cache my windows in order to increase performance. To do that I never close them and just hide instead of closing. All hidden windows are stored in a dictionary, so I can re-use them. When window is opened again I create a new view model and associate it with a cached view.

But there is a problem with that because hidden window keep invoking of CanExecute methods of commands in ViewModels. This leads to performance issues when user opened and closed a lot of windows.

When I set Window.DataContext property to null or do ClearValue(DataContextProperty) I achieve my goal, but there is a problem with that. If I have any two way bindings, they all fired during unbinding from data context. So, some values in my view model become null. I do not want that because in some cases I read properties from ViewModels after hidding of Views.

Can you help me to resolve the main problem (do not call CanExecute methods from hidden windows).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:33:11+00:00Added an answer on June 9, 2026 at 2:33 pm

    I don’t think you get much control over when and where the CommandManager decides to fire off a RequerySuggested event. One way you may be able to mitigate the performance hit would be to have a property on your ViewModel that allows you supress execution of CanExecute. Whenever a View that a ViewModel is bound to goes into hiding, then you can set this property to True

    A simple example

    // Called when a view goes into hiding
    myViewModel.SuppressCommandRequery = True
    

    In your CanExecute handler(s) simply place this line at the beginning of the method

    public bool CanExecuteCommand(Object parameter) {
    
        if (this.SuppressCommandRequery) 
            return;
    
        // Continue processing the event...
    }
    

    I would point out that you need to take special care to then disable the suppression whenever the view came out of hiding. However, in the cases where re-displaying the View results in a new instance of the ViewModel this would not be necessary.

    Alternatively, take a look at this question which talks about using an implementation of a DeletegateCommand from the Prism MVVM Framework. I haven’t used this myself, but it looks like it may address some of your concerns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a WPF application and I'm using the MVVM pattern. I use
I want use MVVM design pattern in WPF and Silverlight Application. Where can i
I'm using Caliburn and the MVVM pattern in a WPF application, and am trying
I'm writing an application in WPF using the MVVM-pattern and will really often use
In my WPF application I use the MVVM pattern together with dependency injection. The
I'm creating a WPF application using the MVVM design pattern that consists of a
I use the MVVM-pattern in my WPF-application. Now I show a dialog with my
So I've been trying to implement the MVVM pattern within a simple WPF application
I'm taking an vanilla WPF application and converting it to use the MVVM pattern.
I'm creating a WPF application using the MVVM design pattern, and I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.