如何绑定Func键< T,T,T>从视图模型依赖属性在XAML? [英] How to bind Func<T,T,T> to dependency property in XAML from view model?

查看:160
本文介绍了如何绑定Func键< T,T,T>从视图模型依赖属性在XAML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AutoFilteredComboBox依赖属性为:

I have a dependency property in my AutoFilteredComboBox as:

 public Func<object, string, bool> theFilter
            {
                get { return (Func<object, string, bool>)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<object, string, bool>), 
                typeof(AutoFilteredComboBox), 
                new UIPropertyMetadata(null));

在XAML绑定是:

 <wc:AutoFilteredComboBox 
                  ItemsSource="{Binding PrimaryInsurance.Companies}"
                  ItemTemplate="{StaticResource CompanyTemplate}"
                  IsEditable="True"
                  IsTextSearchEnabled="True" 
                  TextSearch.TextPath="Companyname"
                  IsTextSearchCaseSensitive="False" 
                  theFilter="{Binding PrimaryInsurance.TheFilter}"  
                  Height="20" HorizontalAlignment="Left" Margin="162,235,0,0" VerticalAlignment="Top" Width="411"  />

和TheFilter在视图模式是:

and TheFilter in the view model is:

 public Func<View_Small_Company, string, bool> TheFilter = (o, prefix) => o.Companyname.StartsWith(prefix);



全部编译没有difficutly,但依赖property-- theFilter - 仍然空

All compiles without difficutly, but the dependency property-- theFilter -- remains null.

什么是做到这一点的语法?这可怎么办?

What is the syntax to do this? Can it be done?

编辑#1。我意识到XAML需求结合特性,所以怎么能函数
作为财产?

Edit#1. I realize the xaml needs properties for binding, so how can a function be passed as a "property" ?

TIA

推荐答案

变化TheFilter财产:

change TheFilter to property:

public Func<View_Small_Company, string, bool> TheFilter { get; set; }

和设置它在构造函数中:

and set it in constructor:

TheFilter = (o, prefix) => ((View_Small_Company)o).Companyname.StartsWith(prefix);

在视图模型从 Func键< TheFilter的变化类型; View_Small_Company,字符串,布尔> ; Func键<对象,字符串,布尔>

这篇关于如何绑定Func键&LT; T,T,T&GT;从视图模型依赖属性在XAML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆