5

I am working on a project using C#/WPF and following MVVM pattern. This project is designed for touch screens.

The major objects of the program are the following:

We have Programs which contain Channels which contain Functions. All these should be able to be copied/cut/pasted.

I have to implement a copy/cut/paste functionnalities and wonder where it is best.

My idea was to implement them in the ViewModel because it seems to me bizarre to have such functionnalities in the Models.

However as Models should contain the full Business logic it would be logical to implement them here but I have a doubt.

What is the best practice for such an implementation? Thanks in advance.

  • are you going to use the clipboard or a custom cut/paste where you store the items in an array or something? – Ewan Oct 10 '18 at 14:15
  • I am going to use a custom cut/paste stored in a List<> of objects. – Maël Pedretti Oct 11 '18 at 4:36
5

I would add a clipboard service

IClipboard
{
    void AddProgram(Program p);
    Program GetProgram(string id);
    ..... etc
}

and inject this into the ViewModel, which would have the copy paste commands bound to your copy/paste keystrokes or whatever

ViewModel
{
    void OnCopy() {
        if(mouseIsOverAProgram) { this.clip.AddProgram(getProgramUnderMouse())
    }
}

Your Models are Program, Channels, Functions etc and shouldn't know about this kind of logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.