How can I use databinding for 3D elements like Visual3D or UIElement3D How can I use databinding for 3D elements like Visual3D or UIElement3D wpf wpf

How can I use databinding for 3D elements like Visual3D or UIElement3D


I found the answer to my own question so I'm posting it here for the benefit of others finding this page later.

To create a binding on a dependency property on something which isn't a framework element, you use the static BindingOperations.SetBinding method. In my case, the end result was something like this:

var visual = new Spherical3D();var tx = new TranslateTransform3D();BindingOperations.SetBinding(tx, TranslateTransform3D.OffsetXProperty,                              new Binding("X") { Source = myDataObject });BindingOperations.SetBinding(tx, TranslateTransform3D.OffsetYProperty,                              new Binding("Y") { Source = myDataObject });BindingOperations.SetBinding(tx, TranslateTransform3D.OffsetZProperty,                              new Binding("Z") { Source = myDataObject });visual.Transform = tx;Children.Add(visual);AddVisual3DChild(visual);