Bind property to method

允我心安 提交于 2019-12-11 01:36:50

问题


I am developing a Windows 8 App in C# and using databinding

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

I can bind the properties of this class to my UI, but the class also has this method I need

public String getProfessorsList()

I would like to be able to bind the method like this...

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

...but obviously this is not allowed. How can I acheve this functionality?


回答1:


Try just adding a getter-property that returns that method:

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

And then bind to that property:

<TextBlock Text="{Binding professorsList}" FontSize="18" />


来源:https://stackoverflow.com/questions/16467043/bind-property-to-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!