小编Sim*_*sen的帖子

在XAML中将静态方法/函数绑定到Func <T>属性

我正在使用XAML创建一个对象树,其中一个节点如下所示:

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; }

}
Run Code Online (Sandbox Code Playgroud)

我的目标是使XAML和代码尽可能干净是必不可少的,现在我不是在为每个函数创建包装器属性:

public static Func<bool> Func1 { get { return Method1; } }

public static bool Method1()
{
    //Do stuff here
    return true; …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf xaml binding c#-4.0

9
推荐指数
2
解决办法
3013
查看次数

标签 统计

binding ×1

c#-4.0 ×1

data-binding ×1

wpf ×1

xaml ×1