0

My goal is to save the xAngle in my ViewModel, after rotating the 3d model.

For some reason, the properties are not updated in the ViewModel

What am I missing here?

Here's my code:

I have the following code in the xaml:

<Window.DataContext>
    <Local:VM />
</Window.DataContext>
<helix:HelixViewport3D x:Name="viewPort3d" ZoomExtentsWhenLoaded="true" CameraRotationMode="Trackball"
                           ShowCoordinateSystem="True" RotateGesture="{Binding RotateGesture, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                           >
    <helix:SpotHeadLight/>
    <ModelVisual3D Content="{Binding The3dModel.Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
        <ModelVisual3D.Transform>
            <Transform3DGroup>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Axis="1,0,0" Angle="{Binding xAngle, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    </RotateTransform3D.Rotation>
                </RotateTransform3D>
            </Transform3DGroup>
        </ModelVisual3D.Transform>
    </ModelVisual3D>
</helix:HelixViewport3D>

And the following code in the ViewModel:

public class VM : INotifyPropertyChanged
{
    private int m_xAngle;

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }

    public int xAngle
    {
        get => m_xAngle;
        set
        {
            m_xAngle = value;
            OnPropertyChanged();
        }
    }
}
Idanis
  • 1,918
  • 6
  • 38
  • 69
  • The XAML/Class code is working well. But your DataContext is refering to a class, and the property you are binding is an instance property. – P.Manthe Nov 13 '17 at 06:28
  • I'm not sure I understand, if I cal `xAngle = 40;` from the `VM`, then it works, the `UI` does change, but if I change the `UI`, then `xAngle` is not updated. – Idanis Nov 13 '17 at 08:22
  • I misunderstood your problem. I think this is because you are binding the Model's transform property (ViewCube is not moving), but with your mouse you are rotating the viewport's camera (ViewCube is moving properly). – P.Manthe Nov 13 '17 at 09:18
  • Ok, that sounds like that's the problem. Do you know then how to bind the camera's rotation to the `VM`? – Idanis Nov 13 '17 at 09:22

0 Answers0