I have a control that has a “Filter” property that expects a function that defines how the contents of the control should be filtered. so far i am setting the filter in code behind as such:
MyControl.Filter = AddressOf Filters.MyFilter
In this example MyFilter is a shared function in the Filters class with the following signature:
Public Shared Function MyFilter(ByVal obj As Object, ByVal text As String) As Boolean
I would like to set this in xaml. I was thinking of setting the Filters.MyFilter as a static resource and setting it that way:
...Filter="{StaticResource myFilter}"/>
but i cant set Filters.MyFilter as a static resource. Any ideas on how to achieve this?
Thanks,
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.MyFilterbut I may be wrong.)Now you can instantiate the FilterOMatic as a resource and reference its FilterProc property via a binding to that resource: