Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueTuple With WPF Binding [duplicate]

why binding to ValueTuple property members (like Item1, Item2 ect) dont work?

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

the code:

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

output window:

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

However in Tuple It always worked.

like image 894
dovid Avatar asked Dec 23 '22 17:12

dovid


1 Answers

As stated in the documentation, Item1 and Item2 of a ValueTuple are fields rather than properties and you can only bind to public properties in WPF.

So if you want to be able to bind to a tuple, you should use the Tuple class.

like image 148
mm8 Avatar answered Dec 30 '22 14:12

mm8