views:

219

answers:

1

My ViewModel:

class ViewModel
{
public string FileName {get;set;}
}

and in my View I bind a label's content to ViewModel's FileName.

now When I do drag-drop a file to my View, How can I update the label's Content property, so that the ViewMode's FileName also get updated via binding?

Directly set the label's Content property won't work, it just simply clear the binding.

+2  A: 

3 quick choices... (Make sure the class implements INotifyPropertyChanged, and FileName is raising this event.)

  1. You can simply pull the VM out of the View's DataContext and during the Drag-and-Drop event set the FileName property of the ViewModel.

  2. Use an AttachedBehavior to allow the Event (Drag-and-Drop) to be used like a Command (http://geekswithblogs.net/HouseOfBilz/archive/2009/08/27/adventures-in-mvvm-ndash-binding-commands-to-any-event.aspx)

  3. Use a Messenger pattern, like MVVMLight's Messenger, to send a Message from the View to the ViewModel and handle the Message on the VM like you would a Command Action.

Agies