2017-06-15 51 views
0

为什么绑定到ValueTuple属性成员(如Item1,Item2等)不工作?ValueTuple与WPF绑定

<TextBlock x:Name="txtTest" Text="{Binding Item1}" /> 

代码:

txtTest.DataContext = ("Item A", "Another Item.."); 

输出窗口:

BindingExpression path error: 'Item1' property not found on 'object' ''ValueTuple`2'

但是在Tuple它总是奏效。

+0

'this.DataContext = new Tuple (“item 1”,“item 2”);'这工作正常。 – AnjumSKhan

+0

@AnjumSKhan对。我已经在我的问题中提到过了。 – dovid

回答

1

documentation,Item1Item2所示,ValueTuple是字段而不是属性,您只能绑定到WPF中的公共属性。

所以,如果你想能够绑定到一个元组,你应该使用Tuple类。