Question: I'm using [WPF NotifyIcon](http://www.codeproject.com/Articles/36468/WPF-NotifyIcon), and actually I'm trying to learn how to display the window after minimize it in the tray. So when the user double click on the icon, the window should appear again. Actually I've created this code:

```
private void MetroWindow_StateChanged(object sender, EventArgs e)
{
   TaskbarIcon tbi = new TaskbarIcon();
   tbi.DoubleClickCommand = Recover(tbi);

     switch (WindowState)
     {
         case WindowState.Minimized:
            Visibility = Visibility.Hidden;
            tbi.Visibility = Visibility.Visible;
            break;
     }
}

private void Recover(TaskbarIcon tbi)
{
    tbi.Visibility = Visibility.Hidden;
    Visibility = Visibility.Visible;
}

```

How you can see when I minimize the window the icon in the tray appear. This working pretty well. I've declared the icon like this:

```
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:local="clr-namespace:Test.Utils.Resources.UIDictionary"
                xmlns:tb="http://www.hardcodet.net/taskbar">

<tb:TaskbarIcon x:Key="NotifyIcon"
              IconSource="/Utils/Images/Test.ico"
              ToolTipText="hello world" />

</ResourceDictionary>

```

Now the problem is that on this line: `tbi.DoubleClickCommand = Recover(tbi);` I get this error:

> 
> Cannot convert the type void in System.Windows.Input.ICommand
> 
> 
> 

It's not possible call a method in this way? Why?

Answer: 
Here is the code for a simple RelayCommand that is what you need

```
public class RelayCommand : ICommand
{
    private Action<object> action;
    public RelayCommand(Action<object> action)
    {
        this.action = action;
    }
    public bool CanExecute(object parameter)
    {
        return true;
    }

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

    public event EventHandler CanExecuteChanged;
}

```

and then, like the other answer its just 

```
tbi.DoubleClickCommand =new RelayCommand(_ => Recover(tbi));

```
Actually, `DoubleClickCommand` is of type [`ICommand`](https://msdn.microsoft.com/en-us/library/system.windows.input.icommand%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396).

You need to set it as [`RelayCommand`](https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.mvvm.relaycommand(v=vs.110).aspx) which is subtype of `ICommand` for it to compile like:

```
 tbi.DoubleClickCommand =new RelayCommand(param => Recover(tbi));

```

You can read more about Relay Commands [on this MSDN link](https://msdn.microsoft.com/en-us/magazine/dn237302.aspx)