I'm working on using XAML to create an object tree and one of the nodes looks like 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 { get { if (string.IsNullOrEmpty(_type)) { _type = GetType().Name; } return _type; } } #endregion public Func<bool> Function { get; set; } } My goal is essential to make the XAML and code behind as clean as possible which isn't the case right now where I'm creating wrapper properties for every function:
public static Func<bool> Func1 { get { return Method1; } } public static bool Method1() { //Do stuff here return true; } and the xaml looks like this for the 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 would like to know if there's a quick and easy way to bind methods/functions to the Func property, I'm talking about the method here NOT the value of the executed method/function. (I can think of using some reflection magic in a valueConverter or inside the ExecuteMethod node/class but that just feels dirty and weird) An example of how I'd like the XAML to 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 for any help in advance and sorry for the bad English grammar, it's not my native language :)