问题
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