Introduction
In my WP8 C#/XAML project I'm using events to notify my view that some async process is done.
I have two types of delegates.
I'm creating events from those delegates and there are several of them notifying my view that some operations are completed or started (in order to show progressbar, navigate to another page, disable some controls et cetera).
In order to raise these events I want to create a private "notification method", which would raise those delegates.
The method i have in mind is in Code Sample below as fireUpEvent
method.
Code Sample
ReturnState enum
public enum ReturnState : int
{
state1 = 0,
... //for the purpose of the presentation
state6 = 15
...
}
Definitions of events & methods
public delegate void LoadingStartedEventHandler();
public delegate void LoadingFinishedEventHandler(ReturnState state);
public event LoadingStartedEventHandler LoadingStarted;
public event LoadingFinishedEventHandler LoadingFinished;
private void fireUpEvent(Action<ReturnState> action, Returnstate parameter)
{
if(action != null)
{
action(parameter);
}
}
private void fireUpEvent(Action action)
{
if(action != null)
{
action();
}
}
Usage
fireUpEvent(LoadingFinished, ReturnState.state1);
Description
The problem is, that when I try to compile I get an error saying:
Argument1: Cannot convert from 'XXXX.YYYY.SomeClass.LoadingFinishedEventHandler' to 'System.Action<XXXX.YYYY.Returnstate>'
I've tried googling, but haven't found any usefull stuff.
Why isn't it convertible?
I'd like to Action<ReturnState>
and Action
in those methods instead of specific delegates, is it possible?
Should I use any other "type" like Action
instead?
The only two I know from this "grooup" are Func
& Action
, are there others?