我尝试从这里使用WPF NotifyIcon:Link
我创建了一个这样的taskbarIcon。
TaskbarIcon tbi = new TaskbarIcon();
tbi.DoubleClickCommand =
我想向DoubleClickCommand添加一个功能。好像它需要一个ICommand。 我怎么能在代码隐藏中做到这一点?
答案 0 :(得分:1)
答案 1 :(得分:0)
//This is command defining
private ICommand myCommand;
public ICommand MyCommand
{
get
{
if (myCommand== null)
myCommand= new RelayCommand(MyMethod);
return myCommand;
}
set { myCommand= value; }
}
//This is your command method
public void MyMethod()
{
}
//This is your xaml
<Button Command="{Binding MyCommand}"/>
如果您需要传递给方法的参数;
myCommand= new RelayCommand<object>(MyMethod);//Change here like this;
并按此更改XAML
//You can pass string parameter
<Button Command="{Binding MyCommand}" CommandParameter="MyParameter"/>
Or
//You can pass a property
<Button Command="{Binding MyCommand}" CommandParameter="{Binding MyProperty}"/>