Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: Regarding file path wildcards Pin
PIEBALDconsult9-Mar-12 10:41
mvePIEBALDconsult9-Mar-12 10:41 
GeneralRe: Regarding file path wildcards Pin
PIEBALDconsult9-Mar-12 15:37
mvePIEBALDconsult9-Mar-12 15:37 
GeneralRe: Regarding file path wildcards Pin
Luc Pattyn9-Mar-12 15:41
sitebuilderLuc Pattyn9-Mar-12 15:41 
GeneralRe: Regarding file path wildcards Pin
PIEBALDconsult9-Mar-12 16:51
mvePIEBALDconsult9-Mar-12 16:51 
QuestionMessage Removed Pin
9-Mar-12 8:18
nassimnastaran9-Mar-12 8:18 
AnswerRe: How to input in DataGridView cell Only Double ... or ... Pin
Ravi Bhavnani10-Mar-12 4:53
professionalRavi Bhavnani10-Mar-12 4:53 
GeneralRe: How to input in DataGridView cell Only Double ... or ... Pin
nassimnastaran10-Mar-12 8:11
nassimnastaran10-Mar-12 8:11 
QuestionCommand Question Pin
Kevin Marois9-Mar-12 7:01
professionalKevin Marois9-Mar-12 7:01 
I created a RelayCommand:

public class RelayCommand<T> : ICommand
{
    readonly Action<T> _execute = null;
    readonly Predicate<T> _canExecute = null;

    public RelayCommand(Action<T> execute)
        : this(execute, null)
    {
    }
    public RelayCommand(Action<T> execute, Predicate<T> canExecute)
    {

        if (execute == null)
            throw new ArgumentNullException("execute");

        _execute = execute;
        _canExecute = canExecute;
    }

    public event EventHandler CanExecuteChanged;

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


I have 2 questions:

I'm trying to have the command pass an enum to the action method:

private ICommand _PerformanceCommand;
public ICommand PerformanceCommand
{
    get
    {
        if (_PerformanceCommand == null)
        {
            _PerformanceCommand = new RelayCommand<ViewCategory>(p => buttonClicked(ViewCategory.Peformance));
        }
        return _PerformanceCommand;
    }
}

private ICommand _SettingsCommand;
public ICommand SettingsCommand
{
    get
    {
        if (_SettingsCommand == null)
        {
            _SettingsCommand = new RelayCommand<ViewCategory>(p => buttonClicked(ViewCategory.Settings));
        }
        return _SettingsCommand;
    }
}


and then

private void buttonClicked(ViewCategory args)
{ 
}


The code throws an exception in the command class on

public void Execute(object parameter)
{
    // parameter is null here
    _execute((T)parameter);
}


1) Not sure why it's null if the command is passing an enum value.

2) How can I refactor the relay command so that it can take a type, or not take a type. In other words

public class RelayCommand : ICommand    // No type
public class RelayCommand<T> : ICommand // Accepts a type


Would I need to separate classes for this?

Thanks
Everything makes sense in someone's mind

Questionlistview Pin
abiir9-Mar-12 5:53
abiir9-Mar-12 5:53 
AnswerRe: listview Pin
Dave Kreskowiak9-Mar-12 7:14
mveDave Kreskowiak9-Mar-12 7:14 
AnswerRe: listview Pin
Abhinav S9-Mar-12 15:45
Abhinav S9-Mar-12 15:45 
Questionstreaming video with c# Pin
sileen_Mohammad9-Mar-12 5:32
sileen_Mohammad9-Mar-12 5:32 
AnswerRe: streaming video with c# Pin
Abhinav S9-Mar-12 5:37
Abhinav S9-Mar-12 5:37 
GeneralRe: streaming video with c# Pin
sileen_Mohammad10-Mar-12 8:37
sileen_Mohammad10-Mar-12 8:37 
QuestionC# ASP.net Update Data into a SQL server database Pin
Mike9889-Mar-12 4:52
Mike9889-Mar-12 4:52 
AnswerRe: C# ASP.net Update Data into a SQL server database Pin
Wes Aday9-Mar-12 5:29
professionalWes Aday9-Mar-12 5:29 
Generali need help???in c# Pin
amira luis9-Mar-12 0:25
amira luis9-Mar-12 0:25 
GeneralRe: i need help???in c# Pin
OriginalGriff9-Mar-12 0:27
mveOriginalGriff9-Mar-12 0:27 
AnswerRe: i need help???in c# Pin
V.9-Mar-12 1:59
professionalV.9-Mar-12 1:59 
GeneralRe: i need help???in c# Pin
Wes Aday9-Mar-12 3:03
professionalWes Aday9-Mar-12 3:03 
Questioninteracting with a webiste in c# Pin
james bradbery8-Mar-12 21:21
james bradbery8-Mar-12 21:21 
AnswerRe: interacting with a webiste in c# Pin
Dave Kreskowiak9-Mar-12 3:16
mveDave Kreskowiak9-Mar-12 3:16 
QuestionThe WebService still returns "Connection Successful" even SQL Server is off. Please Help. Pin
MarkSquall8-Mar-12 18:58
MarkSquall8-Mar-12 18:58 
AnswerRe: The WebService still returns "Connection Successful" even SQL Server is off. Please Help. Pin
Bernhard Hiller8-Mar-12 21:26
Bernhard Hiller8-Mar-12 21:26 
GeneralRe: The WebService still returns "Connection Successful" even SQL Server is off. Please Help. Pin
Sentenryu9-Mar-12 0:21
Sentenryu9-Mar-12 0:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.