[英]How does this ICommand property work?
I would appreciate help with the following code: 希望提供以下代码的帮助:
public static ICommand AddNewRecord { get; set; }
The above code is in the App.xaml.cs file of a WPF application. 上面的代码在WPF应用程序的App.xaml.cs文件中。 What I don't understand: If I'm correct, an interface cannot be instantiated.
我不了解的内容:如果我是正确的,则无法实例化接口。 So what does the above property do?
那么上述属性有什么作用?
Here's code that uses the above property (if that's what it is): 这是使用上述属性的代码(如果是的话):
AddNewRecord = new RCommand<IEnumerable>(list =>
{
var elementType = list.GetType().GetGenericArguments()[0];
// More code I can't disclose.
}, list => list != null);
I am not at liberty to provide the entire code segment. 我不能随意提供整个代码段。
RCommand<IEnumerable>
is a concrete type that implements the ICommand
interface and you can set an ICommand
property to any type that implements the ICommand
interface. RCommand<IEnumerable>
是实现ICommand
接口的具体类型,您可以将ICommand
属性设置为实现ICommand
接口的任何类型。
So the code basically creates an RCommand<IEnumerable>
and sets the AddNewRecord
property to it. 因此,代码基本上创建了一个
RCommand<IEnumerable>
并将其设置为AddNewRecord
属性。
The RCommand<IEnumerable>
class in turn seems to accept an Action<IEnumerable>
that gets invoked when the command is executed and a Predicate<IEnumerable>
that will be returned from the CanExecute
method of the command. RCommand<IEnumerable>
类似乎接受在执行命令时调用的Action<IEnumerable>
和将从命令的CanExecute
方法返回的Predicate<IEnumerable>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.