绑定的方法在WPF数据网格列 [英] Binding a method to a column in datagrid WPF

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

问题描述

我在WPF数据网格被绑定到集合。在一列我要绑定返回字符串,而不是一个属性的公共方法。
是在WPF来解决此问题的方法。

I have a data grid in wpf which is bound to Collection. In one of the columns i want to bind a public method which returns string instead of a property. Is there a way to resolve this in WPF.

顺便提一下它的一种方法绑定。

By the way its one way binding.

推荐答案

我不完全知道你想要做什么和前两个答案的建议可能是(也可能是更多)在您的情况适当的,但只有你回答你的问题,你可以间接绑定到一个方法使用的ObjectDataProvider

I'm not entirely sure what you want to do and the advice of the previous two answers may be (and probably are more) appropriate in your scenario but just you answer your question, you can indirectly bind to a method using an ObjectDataProvider.

<Window>
  <Window.Resources>
    <ObjectDataProvider x:Key="newGuidProvider"
      ObjectType="{x:Type Guid}"
      MethodName="NewGuid"
      />
  </Window.Resources>

  ...

  <TextBlock Text="{Binding Source={StaticResource newGuidProvider}" ... />

  ...

</Window>

这仅仅是一个简单的例子,你可以看看到ObjectDataProvider的,看它是否是正确的在您的方案。 这里是一个很好的资源这说明更多的可能性,如传递参数的方法等等。通过绑定。

This is just a quick example and you can look into the ObjectDataProvider to see if it's right in your scenario. Here is a great resource which shows additional possibilities such as passing parameters to a method etc., via bindings.

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

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