我正在尝试做一些非常简单和基本的事情。如我错了请纠正我:
考虑一个简单的按钮,然后与它关联的方法如下。但是,如果我在 DrawShapeCanExecute() 上更改返回类型,我会得到任何一个(禁用的按钮),那么我会收到一条错误消息:
bool WpfApplication8.DrawingCanvas.DrawShapeCanExecute(object, System.Windows.Input.CanExecuteRoutedEventArgs)' 返回类型错误
public static RoutedCommand DrawShape = new RoutedCommand();
private void DrawShapeCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
} **//Isn't this enough to make it enable?**
private void DrawShape_Executed(object sender, ExecutedRoutedEventArgs e)
{
}
它的 xaml 部分有:
<Button Margin="0,2,2,2" Width="70" Content="Line"
Command="{x:Static local:DrawingCanvas.DrawShape}"
CommandTarget="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type Window}}, Path=DrawingTarget}"
CommandParameter="Line">
</Button>