Binding not working any ab3d elements
#1
I'm trying to bind the heading, attitude and bank of a target position camera to a viewmodel.  
The viewmodel is set as a DataContext to the parent containing the user control containing the ab3d camera and other ab3d elements.
The binding to viewmodel works on wpf elements but does not work on any ab3d elements. Why?
#2
Many objects in the Ab3d.PowerToys library use WPF's DependencyProperties that should support binding - also Heading, Attitude and Bank are implemented with DependencyProperties and therefore can be used with binding.

I am not an expert on binding but anyway to try to help you, I would need more information about which properties do you want to bind to and what method do you use to do that.

However, except for simple cases like camera angles and similar, I would not recommend using binding on 3D objects because binding is very slow and can make the code more complicated. The number of 3D objects can quickly become high and then binding will slow down the whole application. Therefore please use binding with causion.
Andrej Benedik
#3
Hi,

to debug bindings there are multiple ways. If you use Visual Studio (and I assume Rider or other IDE should have something similar), you can look into the output window for logs. Bindings are not very informative so you might need to set them more verbose - Tools -> Options -> Debugging -> Output window (just set Data binding to verbose). This should tell you if and why the bindings failed.

You can also use tools like snoopwpf/snoopwpf: Snoop - The WPF Spy Utility (github.com) that attaches to the process and you can identify if the view model is truly correct.

In the case you are using VS 2019, then the recent versions should also have xaml bindings failures window (under Debug->Windows).
#4
The trick is that the binding mode isn't setup by default for TwoWay. If you set this explicitly it works just fine otherwise changes in the source don't do anything to the actual camera position.

Code:
<cameras:TargetPositionCamera
          Heading="{Binding Heading, Mode=TwoWay}"
          Attitude="{Binding Attitude, Mode=TwoWay}"
          Distance="{Binding Distance, Mode=TwoWay}"
          ShowCameraLight="Always"
          TargetViewport3D="{Binding ElementName=MainViewport}"/>
  


Forum Jump:


Users browsing this thread:
1 Guest(s)