0

I'm trying to bind 3 TextBoxes (as a first step, but really 3 DataGrid columns) to components of a Vector3D property. Notice, though, that Vector3D is a struct and is thus value-type.

The idea for the binding is to be able to edit a Vector3D property, such that each vector component X, Y, Z is individually editable.

The following does not work:

<TextBox Text="{Binding Position.X}"/>
<TextBox Text="{Binding Position.Y}"/>
<TextBox Text="{Binding Position.Z}"/>

Is this possible without rewriting my models to wrap a Vector3D struct with a class?

New Dev
  • 48,427
  • 12
  • 87
  • 129
  • What happens if you just try it? – Clemens Jul 23 '13 at 07:14
  • @Clemens, The values revert back to the original and no change is made. Binding traces show something related to deactivating/detaching, which I presume means that the change is made to a copy of the Property, rather than to the original. – New Dev Jul 23 '13 at 07:17
  • You need commit the edits – Gayot Fow Jul 23 '13 at 08:02
  • @GarryVass, Your solution didn't work for me in the [related question](http://stackoverflow.com/questions/17796224/datagrid-reverts-the-values-back-to-original-when-leaving-row) I asked. – New Dev Jul 23 '13 at 08:06
  • Yes, it actually works. And it's the same answer for this question. It also looks like you need to fix your binding configuration here. Along with the INPC implementation. – Gayot Fow Jul 23 '13 at 08:43
  • @GarryVass, Let me try it again on this simplified version. But can you tell me, why is it that I need to commit the edits explicitly. Is this because of a struct? – New Dev Jul 23 '13 at 08:45
  • You need to commit edits explicitly because Microsoft says that you will get random/unpredictable results otherwise. – Gayot Fow Jul 23 '13 at 09:14
  • @GarryVass, in which cases? Can you give a link where they talk about it? – New Dev Jul 23 '13 at 09:21
  • Best approach. Get the class working as described and then fill in if there's any missing bits. You jumped the gun on thinking it didn't work :) – Gayot Fow Jul 23 '13 at 10:00

0 Answers0