绑定AxisAngleRotation3D以保存角度变化

时间:2017-11-12 18:46:17

标签: c# wpf mvvm viewport3d modelvisual3d

我的目标是在旋转3D模型后将xAngle保存在我的ViewModel中。

由于某些原因,properties

中未更新ViewModel

我在这里缺少什么?

这是我的代码:

我在 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>

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();
        }
    }
}

0 个答案:

没有答案