为什么绑定到
ValueTuple
属性成员(如Item1、Item2等)不起作用?<TextBlock x:Name="txtTest" Text="{Binding Item1}" />
代码:
txtTest.DataContext = ("Item A", "Another Item..");
输出窗口:
绑定表达式路径错误:在“ValueTuple`2”对象上未找到属性“Item1”。
然而,在 Tuple
中它总是可以工作的。
this.DataContext = new Tuple<string, string>("item 1", "item 2");
运行良好。 - AnjumSKhan