How to handle drag/drop without violating MVVM principals?

前端 未结 5 691
时光说笑
时光说笑 2020-12-24 07:40

Currently I have in my XAML


All of

5条回答
  •  悲&欢浪女
    2020-12-24 07:55

    There are libraries for this such as gong and similar snippets on various blog articles.

    However, you shouldn't get too hung up on having absolutely no code-behind. For example, this is still MVVM in my book:

    void ButtonClicked(object sender, EventArgs e)
    {
        ((MyViewModel) this.DataContext).DoSomething();
    }
    

    A command binding might be a better choice, but the logic is definitely in the viewmodel. With something like Drag and Drop, it's more variable where you want to draw the line. You can have code-behind interpret the Drag Args and call methods on the viewmodel when appropriate.

提交回复
热议问题