Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Q] Any simple usage of Collection undo/redo? #5

Closed
tangible-idea opened this issue Feb 15, 2018 · 1 comment
Closed

[Q] Any simple usage of Collection undo/redo? #5

tangible-idea opened this issue Feb 15, 2018 · 1 comment

Comments

@tangible-idea
Copy link

tangible-idea commented Feb 15, 2018

I'm trying to create a system to redo/undo with the whole canvas elements of my program with muf.
canvas elements is bound to ObservableCollection<FrameworkElement> and everytime user add/remove the element, it goes to the property

public CustomCollection<FrameworkElement> m_CanvasElements = new CustomCollection<FrameworkElement>();
    public CustomCollection<FrameworkElement> CanvasElements
    {
        get {
            return m_CanvasElements; }
        set {

            m_CanvasElements = value;
            OnPropertyChanged("CanvasElements");
        }
    }

And here's what I've tried to do. I made an inherited class of ObservableCollection to use an NotifyCollectionChangedEventArgs as a parameter.

public class CustomCollection<T> : ObservableCollection<T>, ICloneable
    {
        public event EventHandler<NotifyCollectionChangedEventArgs> ItemAdded;

        public CustomCollection()
        {
            CollectionChanged += MyObservableCollection_CollectionChanged;
        }

        void MyObservableCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {

            DefaultChangeFactory.Current.OnCollectionChanged(this, "CanvasElements", MainWindow.VM.m_CanvasElements, e);
         ...
        }

I have tried both OnCollectionChanged and GetCollectionChange. and it seems doesn't work.
Currently, OnChanging is working exactly that I expected.
Any ideas?

@tangible-idea
Copy link
Author

tangible-idea commented Feb 15, 2018

My mistake
I had to change
DefaultChangeFactory.Current.OnCollectionChanged(this, "CanvasElements", MainWindow.VM.m_CanvasElements, e);
to
DefaultChangeFactory.Current.OnCollectionChanged(MainWindow.VM, "CanvasElements", MainWindow.VM.m_CanvasElements, e);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant