Beispiel #1
0
        public MainWindowVM()
        {
            //Call the button command binding class to
            //register the button click event with the handler
            DogClick  = new ButtonCommandBinding(SelectDog);
            DuckClick = new ButtonCommandBinding(SelectDuck);

            //Enable the button click event
            DogClick.IsEnabled  = true;
            DuckClick.IsEnabled = true;
        }
        /// <summary>
        /// Builds a new command binding.
        /// </summary>
        /// <typeparam name="TView">The type of the view the new binding binds to.</typeparam>
        /// <typeparam name="TControl">The type of the control the new binding binds to.</typeparam>
        /// <typeparam name="TViewModel">The type of the viewmodel the new binding binds to.</typeparam>
        /// <param name="view">The view to bind to.</param>
        /// <param name="control">The control to bind to.</param>
        /// <param name="viewModel">The viewmodel to bind to.</param>
        /// <param name="viewModelProperty">The binding source property (the property on the viewmodel to bind to).</param>
        /// <exception cref="NotSupportedException">Thrown when an unsupported control is encountered.</exception>
        /// <returns>A new command binding.</returns>
        internal static Binding <TView> BuildCommand <TView, TControl, TViewModel>(TView view,
                                                                                   TControl control, TViewModel viewModel, Expression <Func <TViewModel, ICommand> > viewModelProperty) where TViewModel : INotifyPropertyChanged
        {
            Binding <TView> result = null;

            // type of command binding is derived from the type of control
            if (typeof(TControl) == typeof(Button))
            {
                result = new ButtonCommandBinding <TView, TViewModel>(view, control as Button,
                                                                      viewModel, viewModelProperty);
            }

            //if (typeof(TControl) == typeof(ToolStripMenuItem))
            //{
            //    result = new ToolStripMenuItemCommandBinding<TView, TViewModel>(view, control as ToolStripMenuItem,
            //        viewModel, viewModelProperty);
            //}

            //if (typeof(TControl) == typeof(ToolStripButton))
            //{
            //    result = new ToolStripButtonCommandBinding<TView, TViewModel>(view, control as ToolStripButton,
            //        viewModel, viewModelProperty);
            //}

            if (typeof(TControl) == typeof(MenuItem))
            {
                result = new MenuItemCommandBinding <TView, TViewModel>(view, control as MenuItem,
                                                                        viewModel, viewModelProperty);
            }

            if (result != null)
            {
                result.HookEvents();
                return(result);
            }

            // unsupported control type
            throw new NotSupportedException(string.Format("Command binding is not supported for {0}", typeof(TControl)));
        }
 public GotoPageViewModel(Action<string> gotoPageAction)
 {
     GotoPageCommand = new ButtonCommandBinding<string>(gotoPageAction);
 }
Beispiel #4
0
 public GotoPageViewModel(Action <string> gotoPageAction)
 {
     GotoPageCommand = new ButtonCommandBinding <string>(gotoPageAction);
 }