0
這是一個這樣的基本問題,但我必須問。如何執行Silverlight ICommand?
在SL,我有這樣的XAML:
<UserControl.Resources>
<local:Commands x:Key="MyCommands" />
</UserControl.Resources>
<Button Content="Click Me"
Command="{Binding Path=Click, Source={StaticResource MyCommands}}"
CommandParameter="Hello World" />
而這後面的代碼:
public class Commands
{
public ClickCommand Click = new ClickCommand();
public sealed class ClickCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
MessageBox.Show(parameter.ToString());
}
}
}
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}
但是,當我按一下按鈕,命令的execute()是從來沒有發射。
有沒有訣竅呢?