Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Change the following event from user control to viewModel

$
0
0
Hi 

I need to move this event from the user control to the viewModel,I have read the following link 
but not sure that I got it since command are true or false,my question is assume that I have the following event 
how should I change it to the viewModel.? 


Please assist ,Im really stuck !!!!
 

http://blog.magnusmontin.net/2013/06/30/handling-events-in-an-mvvm-wpf-application/




        private void DropText_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var textBox = (TextBox) sender;
            if (textBox == null) return;
            textBox.Focus();
            var dataObject = new DataObject((textBox).Text);
            dataObject.SetData(DragSource, sender);
            DragDrop.DoDragDrop(textBox, dataObject, DragDropEffects.Copy | DragDropEffects.Move);
        }



<TextBox x:Name="Job"  
        			AcceptsReturn="True"
        			AllowDrop="True" 
        			PreviewMouseDown="DropText_PreviewMouseDown"
        			SelectionChanged="listbox_SelectionChanged"
        			HorizontalAlignment="Left" 





    internal class RelayCommand : ICommand
    {
        readonly Action _execute;
        readonly Func<bool> _canExecute;

        public RelayCommand(Action execute)
            : this(execute, null)
        {
        }

        public RelayCommand(Action execute, Func<bool> canExecute)
        {
            if (execute == null)
                throw new ArgumentNullException("execute");
            _execute = execute;
            _canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute();
        }

        public event EventHandler CanExecuteChanged
        {
            add
            {
                if (_canExecute != null)
                    CommandManager.RequerySuggested += value;
            }
            remove
            {
                if (_canExecute != null)
                    CommandManager.RequerySuggested -= value;
            }
        }

        public void Execute(object parameter)
        {
            _execute();
        }

        public event EventHandler CanExecuteChange;
        public void RaiseCanExecuteChange()
            {
            if (CanExecuteChange != null)
                CanExecuteChange(this, new EventArgs());
            }



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>