Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF .Net Core Relay Command with Parameters

WPF .Net Core Relay Command with Parameters

Scheduled Pinned Locked Moved WPF
csharpwpfasp-netdotnetwcf
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    Following [this SO article](https://stackoverflow.com/questions/34996198/the-name-commandmanager-does-not-exist-in-the-current-context-visual-studio-2), I'm trying to create a relay command that takes parameters:

    <ctrls:MaroisHyperlink LinkText="Forgot Password?"
    Foreground="SteelBlue"
    Margin="30,0,0,0"
    Height="20">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="LinkClicked">
            <i:InvokeCommandAction Command="{Binding ForgotPasswordClickedCommand}"
                                    CommandParameter="True"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    

    </ctrls:MaroisHyperlink>

    Here's my RelayCommand class:

    namespace Marois.Framework.Core.Utilities
    {
    public class RelayCommand<T> : ICommand
    {
    private readonly Action<T> execute;

        private readonly Func<T, bool> canExecute;
    
        public RelayCommand(Action<T> execute)
            : this(execute, null)
        {
        }
    
        public RelayCommand(Action<T> execute, Func<T, bool> canExecute)
        {
            ArgumentNullException.ThrowIfNull(execute);
    
            this.execute = execute;
            this.canExecute = canExecute;
            this.RaiseCanExecuteChangedAction = RaiseCanExecuteChanged;
    
            SimpleCommandManager.AddRaiseCanExecuteChangedAction(ref RaiseCanExecuteChangedAction);
        }
    
        ~RelayCommand()
        {
            RemoveCommand();
        }
    
        public void RemoveCommand()
        {
            SimpleCommandManager.RemoveRaiseCanExecuteChangedAction(RaiseCanExecuteChangedAction);
        }
    
        bool ICommand.CanExecute(object? parameter)
        {
            return canExecute((T)parameter);
        }
    
        public void Execute(object? parameter)
        {
            if (CanExecute(parameter))
            {
                execute((T)parameter);
            }
        }
    
        public bool CanExecute(object? parameter)
        {
            return canExecute == null ? true : canExecute((T)parameter);
        }
    
    
        public void RaiseCanExecuteChanged()
        {
            var handler = CanExecuteChanged;
            if (handler != null)
            {
                handler(this, new EventArgs());
            }
        }
    
        private readonly Action RaiseCanExecuteChangedAction;
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups