如何将Func 绑定到视图模型的XAML中的依赖属性?
我在AutoFilteredComboBox中有一个依赖属性:
public Func theFilter { get { return (Func)GetValue(theFilterProperty); } set { SetValue(theFilterProperty, value); } } // Using a DependencyProperty as the backing store for theFilter. This enables animation, styling, binding, etc... public static readonly DependencyProperty theFilterProperty = DependencyProperty.Register( "theFilter", typeof(Func), typeof(AutoFilteredComboBox), new UIPropertyMetadata(null));
XAML中的绑定是:
视图模型中的TheFilter是:
public Func TheFilter = (o, prefix) => o.Companyname.StartsWith(prefix);
所有编译都没有difficutly,但依赖属性 – theFilter – 仍为null。
这样做的语法是什么? 可以吗?
编辑#1。 我意识到xaml需要绑定属性,那么如何将函数作为“属性”传递?
TIA
将TheFilter更改为property:
public Func TheFilter { get; set; }
并在构造函数中设置它:
TheFilter = (o, prefix) => ((View_Small_Company)o).Companyname.StartsWith(prefix);
从Func
更改视图模型中的TheFilter类型到Func