将属性绑定到方法
本文关键字:方法 绑定 属性 | 更新日期: 2023-09-27 18:12:58
我正在用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" />
…但显然这是不允许的。如何实现此功能?
尝试添加一个返回该方法的getter属性:
public string ProfessorsList { get { return this.getProfessorsList(); } }
然后绑定到属性:
<TextBlock Text="{Binding professorsList}" FontSize="18" />