I have a delegate type:
public delegate bool CheckFormatDelegate(int row, int col, ref string text);
This has been used in a Property on a Xaml object:
public virtual CheckFormatDelegate CheckFormat { get; set; }
I set the property value to one of a group of delegates, for example:
public class FCS
{
public static bool FormatDigitsOnly(int row, int col, ref string text)
{
...
}
}
If I set the property in codebehind, all is well. However, if I set it in Xaml:
<mui:DXCell CheckFormat="mui:FCS.FormatDigitsOnly"/>
when I run my app I get an exception: “‘CheckFormatDelegate’ type does not have a public TypeConverter class.”. Does anyone know if there’s a built in set of converters/markup extensions like the ones used for RoutedEvent? Or is there some other way around this?
The error you are getting is because it is trying to convert a string into something meaningful to the XAML compiler. You might be able to create a type converter for it (implemented with reflections), but there are simpler ways to work around this.
Use the
x:Staticmarkup extension.See the MSDN docs:
http://msdn.microsoft.com/en-us/library/ms742135.aspx
According to that page:
I’m guessing your custom delegate does not, and would require you to use
x:Static.Edit
I tried it out, and it doesn’t seem to work on methods, as you mentioned. But it does work against properties. Here is a work-around:
Edit 2
I don’t want to steal their answers (so please up-vote them instead, unless you prefer the property work-around), but here is a question that has an even better solution for you:
Binding of static method/function to Func<T> property in XAML