S
shapper
Hello,
I am not sure if this question is for this forum. It is a WPF C#
question.
I implemented a ICommand interface as follows:
public class SetupCommand : ICommand {
Boolean CanExecute(Object parameter) {
return true;
} // CanExecute
void Execute(Object parameter) {
Setup setup = new Setup();
setup.Run();
} // Execute
} // SetupCommand
On my WPF window I am adding a menu at runtime:
Menu menu = new Menu();
menu.Items.Add(new MenuItem { Command = SetupCommand, Header =
"Setup" });
In Command of the menu item it says:
System.Windows.Input.ICommand MenuItem Command
Gets or sets the command associated to the menu item. This is a
dependency property.
I get the following error:
'SetupCommand' is a 'type' but is used like a 'variable'.
I also tried to wrap the SetupCommand in a MenuCommands class and
expose it through a property:
public class MenuCommands {
public ICommand Setup { get { return new SetupCommand(); } }
public class SetupCommand : ICommand {
Boolean CanExecute(Object parameter) {
return true;
} // CanExecute
void Execute(Object parameter) {
//Setup setup = new Setup();
//setup.Run();
} // Execute
} // SetupCommand
}
And on menu item I try:
menu.Items.Add(new MenuItem { Command = MenuCommands.Setup, Header =
"Setup" });
This does not work either.
It works if I use something like:
menu.Items.Add(new MenuItem { Command = ApplicationCommands.Close,
Header = "Close" });
ApplicationCommands is defined in System.Windows.Input.
What am I doing wrong in my implementation?
Thanks.
Miguel
I am not sure if this question is for this forum. It is a WPF C#
question.
I implemented a ICommand interface as follows:
public class SetupCommand : ICommand {
Boolean CanExecute(Object parameter) {
return true;
} // CanExecute
void Execute(Object parameter) {
Setup setup = new Setup();
setup.Run();
} // Execute
} // SetupCommand
On my WPF window I am adding a menu at runtime:
Menu menu = new Menu();
menu.Items.Add(new MenuItem { Command = SetupCommand, Header =
"Setup" });
In Command of the menu item it says:
System.Windows.Input.ICommand MenuItem Command
Gets or sets the command associated to the menu item. This is a
dependency property.
I get the following error:
'SetupCommand' is a 'type' but is used like a 'variable'.
I also tried to wrap the SetupCommand in a MenuCommands class and
expose it through a property:
public class MenuCommands {
public ICommand Setup { get { return new SetupCommand(); } }
public class SetupCommand : ICommand {
Boolean CanExecute(Object parameter) {
return true;
} // CanExecute
void Execute(Object parameter) {
//Setup setup = new Setup();
//setup.Run();
} // Execute
} // SetupCommand
}
And on menu item I try:
menu.Items.Add(new MenuItem { Command = MenuCommands.Setup, Header =
"Setup" });
This does not work either.
It works if I use something like:
menu.Items.Add(new MenuItem { Command = ApplicationCommands.Close,
Header = "Close" });
ApplicationCommands is defined in System.Windows.Input.
What am I doing wrong in my implementation?
Thanks.
Miguel