将属性绑定到方法

时间:2013-05-09 16:57:50

标签: c# xaml data-binding windows-8 windows-runtime

我正在使用C#开发Windows 8应用程序并使用数据绑定

<CollectionViewSource
    x:Name="departments"
    Source="{Binding Departments}"
    d:Source="{Binding AllGroups, Source={d:DesignInstance Type=data:Department, IsDesignTimeCreatable=True}}"/>

我可以将此类的属性绑定到我的UI,但该类也有我需要的方法

public String getProfessorsList()

我希望能够像这样绑定方法......

<TextBlock Text="{Binding getHeads()}" FontSize="18" />

......但显然这是不允许的。我怎样才能获得这个功能?

1 个答案:

答案 0 :(得分:3)

尝试添加一个返回该方法的getter-property:

public string ProfessorsList { get { return this.getProfessorsList(); } }

然后绑定到该属性:

<TextBlock Text="{Binding professorsList}" FontSize="18" />
相关问题