在转换器中获取上下文?

I have a usercontrol whose the context is a given object Foo.

I have a textbox in readonly mode, whose the text changes according to a selected value in a combobox (which is bind two-way). The value of the textbox uses the values of a lot of fields in Foo.

For now, I have written a converter Text="{Binding ComboboxValue, Converter={StaticResource MyTextConverter}}, and code-behind, according to the ComboboxValue, I need to return a string composed of other values of Foo. The problem is I can't access the DataContext in the converter, and I can't pass it. If I bind the context without Path (using Text="{Binding Converter={StaticResource ConnectionStringTextConverter}}), it won't trigger every time my value in the combobox changes (normal).

So, is it possible to it that way ? Or I'm forced to use the Selected event of the combobox ?

Thanks

PS: Actually, what I need is to bind the Text property of the textbox on my DataContext (no Path), but I need the binding to be evaluate each time a property change of the object change. Is this possible ?

#0

You could use the DataContextProxy utility class like this:

Text={Binding ComboBoxValue, Converter={StaticResource MyTextConverter}, ConverterParameter={StaticResource DataContextProxy}}

and then in your converter grab the converter parameter and cast it to a DataContextProxy and use its DataSource property.

推荐文章

使用VS2008测试ASP.NET MVC应用程序时未更新JS文件

使用VS2008测试ASP.NET MVC应用程序时未更新JS文件

推荐文章

Cocoa帮助程序

Cocoa帮助程序

推荐文章

是重置密码还是将丢失的密码发回?

是重置密码还是将丢失的密码发回?

推荐文章

导出Fluent Nhibernate模式和Alter表

导出Fluent Nhibernate模式和Alter表

推荐文章

SQL Server 2008-忽略空值

SQL Server 2008-忽略空值

推荐文章

Mcrypt已安装,但未显示在PHPINFO上

Mcrypt已安装,但未显示在PHPINFO上

推荐文章

在Drupal中将FCKEditor限制为一种输入格式?

在Drupal中将FCKEditor限制为一种输入格式?

推荐文章

使用样式“overflow:hidden”和“border collapse”,表的上边框将消失

使用样式“overflow:hidden”和“border collapse”,表的上边框将消失

推荐文章

奇WCF问题

奇WCF问题

推荐文章

SQL Server 2008-布尔变量更改查询

SQL Server 2008-布尔变量更改查询

推荐文章

如何声明返回“anything”的泛型集合的方法(C#)

如何声明返回“anything”的泛型集合的方法(C#)

推荐文章

c#UDP检查是否有完整的数据包?

c#UDP检查是否有完整的数据包?

推荐文章

JSLint错误的解决方案

JSLint错误的解决方案

推荐文章

C中的等效字符*#

C中的等效字符*#

推荐文章

方案列表等价性比较

方案列表等价性比较

推荐文章

基于iPhone的绝对马赫时间是多少

基于iPhone的绝对马赫时间是多少