wpf - Binding of static method/function to Func<T> property in XAML -
i'm working on using xaml create object tree , 1 of nodes looks this:
public class executemethod : inode { #region implementation of inode public bool evaluate() { return function != null && function(); } public string name { get; set; } private string _type; public string type { { if (string.isnullorempty(_type)) { _type = gettype().name; } return _type; } } #endregion public func<bool> function { get; set; } }
my goal essential make xaml , code behind clean possible isn't case right i'm creating wrapper properties every function:
public static func<bool> func1 { { return method1; } } public static bool method1() { //do stuff here return true; }
and xaml looks above code:
<root xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="clr-namespace:xamlbt;assembly=xamlbt" xmlns:d="clr-namespace:testbt;assembly=testbt"> <root.child> <sequence name="sequence1" > <executemethod name="e1.1" function="{x:static d:program.func1}" /> <selector name="selector1" > <executemethod name="e2.1" function="{x:static d:program.func1}" /> </selector> </sequence> </root.child>
i know if there's quick , easy way bind methods/functions func property, i'm talking method here not value of executed method/function. (i can think of using reflection magic in valueconverter or inside executemethod node/class feels dirty , weird) example of how i'd xaml look:
<root xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="clr-namespace:xamlbt;assembly=xamlbt" xmlns:d="clr-namespace:testbt;assembly=testbt"> <root.child> <sequence name="sequence1" > <executemethod name="e1.1" function="{x:static d:program.method1}" /> <selector name="selector1" > <executemethod name="e2.1" function="{x:static d:program.method1}" /> </selector> </sequence> </root.child>
thanks in advance , sorry bad english grammar, it's not native language :)
i can think of couple ways make cleaner there isn't binding syntax asking. i'm guessing happy writing own markup extension make {d:staticmethod program.method1}
, have use reflection, trivial cache , better value converter.
Comments
Post a Comment