I'm learning MVVM and PRISM and trying to handle the Drop and DragEnter events for a TextBox.
I have managed to do this successfully for a button click
public ButtonsViewModel()
{
//If statement is required for viewing the MainWindow in design mode otherwise errors are thrown
//as the ButtonsViewModel has parameters which only resolve at runtime. I.E. events
if (!(bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)
{
svc = ServiceLocator.Current;
events = svc.GetInstance<IEventAggregator>();
events.GetEvent<InputValidStatus>().Subscribe(SetInputStatus);
StartCommand = new DelegateCommand(ExecuteStart, CanExecute).ObservesProperty(() => InputStatus);
ExitCommand = new DelegateCommand(ExecuteExit);
}
}
private bool CanExecute()
{
return InputStatus;
}
private void ExecuteStart()
{
InputStatus = true;
ERA Process = new ERA();
Proces.Run();
}
This works fine and have no issues with doing this for other events which do not take EventArgs. So the Drop method will be fine to implement as I don't need to interact with the EventArgs.
However with the Textbox_DragEnter event it sets the DragDropEffects of the TextBox
private void TextBox_DragEnter(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Copy;
}
My first thought was to create a ICommand and bind it to the TextBox_DragEnter event and within the ViewModel have this update a DragDropEffects property. But I cant see how to bind the effect to the textbox.
I may be thinking about this wrong. What is the proper way to do this?
I know that I can set these events easily in the code behind but I would prefer not to do this and keep it purely using the MVVM Pattern
Hope this makes sense.