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 407733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:37:25+00:00 2026-05-12T17:37:25+00:00

In my previous projects, I have already implemented undo system in c++, and I

  • 0

In my previous projects, I have already implemented undo system in c++, and I know how it work. I am also aware of the Command pattern.

I will be implementing a C#/WPF desktop application and would like to base my design on the M-V-VM pattern.

The application will:

  • be relatively a small project (2-3 weeks estimated work for 1 dev)
  • have a simple data model with persistence (linq to XML)
  • support undo/redo

I was wondering if anybody has experience with implementing an undo system when following the M-V-VM pattern. How would it fit in it? How can it benefit from the INotifyPropertyChanged and INotifyCollectionChanged notifications so minimal work is required when implementing the Models (business objects).

I would think the undo system would some kind of integrated into the ViewModel layer, as it is a UI state.

Any thought?

  • 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-05-12T17:37:25+00:00Added an answer on May 12, 2026 at 5:37 pm

    Here is the solution I used for my project. The solution proved to be working perfectly.

    The system is using undo event objects, where each undo event know how to undo and redo itself.

    interface IUndoEvent
    {
        void Undo();
        void Redo();
    }
    

    I was able to build the system by implementing only 2 undo events: One for property changes; one for collection changes.

    The idea is that those events implement the Undo/Redo by modifying the model directly.

    class PropertyChangeUndoEvent : IUndoEvent
    {
        private ModelBase _target;
        private string _propertyName;
        private object _oldValue;
        private object _newValue;
    
        public PropertyChangeUndoEvent(ModelBase target, string propertyName, object oldValue, object newValue)
        {
            _target = target;
            _propertyName = propertyName;
            _oldValue = oldValue;
            _newValue = newValue;
        }
    
        public void Undo()
        {
            SetValue(_oldValue);
        }
    
        public void Redo()
        {
            SetValue(_newValue);
        }
    
        private void SetValue(object value)
        {
            // Set Value on the _target using reflection (_propertyName)
        }
    }
    

    The ViewModel take care of creating undo events by calling ViewModelBase functions:

    class MyViewModel : ViewModelBase
    {
        public string Name
        {
            get { return _model.Name; }
    
            // The SetValue will create a undo event, and push it to the UndoManager
            set { SetValue(_model, "Name", value); }
        }
    }
    

    Finally, there is a UndoManager (project singleton) that stores the undo stack and the redo stack.

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

Sidebar

Ask A Question

Stats

  • Questions 234k
  • Answers 234k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Prior to Android 2.0 you need to query Contacts.ContactMethods.CONTENT_URI to… May 13, 2026 at 6:00 am
  • Editorial Team
    Editorial Team added an answer It's quite common to build large applications using different langauges… May 13, 2026 at 6:00 am
  • Editorial Team
    Editorial Team added an answer If it's not too late you could use a framework… May 13, 2026 at 6:00 am

Related Questions

I am developing an application for the Android platform which contains 1000+ image filters
I've made it a personal rule to inherit every UI control before using it.
currently we are developing an app in which we use database table to store
I use git to interface with an SVN repository. I have several git branches

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.