You cannot do this directly. XAML doesn't provide a way to refer to functions, other than as event handlers.
You can do it indirectly, by creating an object that has a property of predicate type:
public class FilterOMatic
{
public Predicate<int> FilterProc
{
get { return n => (n % 2) == 0; }
}
}
(Pardon the C#-ism -- I'm not too familiar with the VB syntax for returning functions. I think it would be something like Return AddressOf Filters.MyFilter but I may be wrong.)
Now you can instantiate the FilterOMatic as a resource and reference its FilterProc property via a binding to that resource:
发布评论
评论(1)
您不能直接执行此操作。除了作为事件处理程序之外,XAML 不提供引用函数的方法。
您可以通过创建一个具有谓词类型属性的对象来间接做到这一点:(
请原谅 C# 主义——我不太熟悉用于返回函数的 VB 语法。我认为它类似于
Return AddressOf Filters.MyFilter
但我可能是错的。)现在您可以将 FilterOMatic 实例化为资源,并通过与该资源的绑定引用其 FilterProc 属性:
You cannot do this directly. XAML doesn't provide a way to refer to functions, other than as event handlers.
You can do it indirectly, by creating an object that has a property of predicate type:
(Pardon the C#-ism -- I'm not too familiar with the VB syntax for returning functions. I think it would be something like
Return AddressOf Filters.MyFilter
but I may be wrong.)Now you can instantiate the FilterOMatic as a resource and reference its FilterProc property via a binding to that resource: