Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm using
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?
–
–
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
.
You need to set it as RelayCommand
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
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.