绑定属性的方法 [英] Bind property to method

查看:169
本文介绍了绑定属性的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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}}"/>



我这个类的属性绑定到我的UI,但类也有这种方法,我需要

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" />



...但显然这是不允许的。我怎样才能acheve此功能

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

推荐答案

尝试只是增加一个getter属性,返回该方法:

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" />

这篇关于绑定属性的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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