2017-06-15 94 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類。