Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
Drag and Drop MVVM
posted

Hi,

I'm trying to use the drop manager in our MVVM WPF application, and when I try to add a DragStart or DragDrop event I keep getting the error message that the method must be part of the code behind.

This, of course, would break our MVVM pattern to put code in the code-behind of the view.  Is there a workaround, and do you intend to support MVVM in the future?

Thanks.

Parents
No Data
Reply
  • 195
    posted

    drop manager is not part of the visual tree, so there is no normal way to bind to view model property.

    only workaround i found for me is to use freezable data context proxy:

    <ns:BindingProxy x:Key="BindingProxy" Data="{Binding}"></ns:BindingProxy>

    and

    <command:EventToCommand Command="{Binding Path=Data.DragStartCommand, Source={StaticResource BindingProxy}}" 

    hope this helps.

Children
No Data