<ModelVisual3D x:Class="OrbitalSimulator.View.OrbitModelVisual3D" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" x:Name="Model"> <ModelVisual3D.Transform> <Transform3DGroup> <ScaleTransform3D ScaleX="{Binding Scale.X, ElementName=Model}" ScaleY="{Binding Scale.Y, ElementName=Model}" ScaleZ="{Binding Scale.Z, ElementName=Model}"/> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D Angle="{Binding EulerAngles.Yaw, ElementName=Model}" Axis="0 0 1" /> </RotateTransform3D.Rotation> </RotateTransform3D> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D Angle="{Binding EulerAngles.Pitch, ElementName=Model}" Axis="0 1 0" /> </RotateTransform3D.Rotation> </RotateTransform3D> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D Angle="{Binding EulerAngles.Roll, ElementName=Model}" Axis="1 0 0" /> </RotateTransform3D.Rotation> </RotateTransform3D> <TranslateTransform3D OffsetX="{Binding Radius, ElementName=Model}"/> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D Axis="{Binding OrbitAxis, ElementName=Model}" Angle="{Binding CourseAngle, ElementName=Model}" /> </RotateTransform3D.Rotation> </RotateTransform3D> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D Axis="0 1 0" Angle="{Binding Latitude, ElementName=Model}" /> </RotateTransform3D.Rotation> </RotateTransform3D> <RotateTransform3D> <RotateTransform3D.Rotation> <AxisAngleRotation3D Axis="0 0 1" Angle="{Binding Longitude, ElementName=Model}" /> </RotateTransform3D.Rotation> </RotateTransform3D> </Transform3DGroup> </ModelVisual3D.Transform>
public partial class OrbitModelVisual3D : ModelVisual3D { public OrbitModelVisual3D() { InitializeComponent(); } public Vector3D OrbitAxis { get { return (Vector3D)GetValue(OrbitAxisProperty); } set { SetValue(OrbitAxisProperty, value); } } public static readonly DependencyProperty OrbitAxisProperty = DependencyProperty.Register("OrbitAxis", typeof(Vector3D), typeof(OrbitModelVisual3D)); public double Radius { get { return (double)GetValue(RadiusProperty); } set { SetValue(RadiusProperty, value); } } public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(OrbitModelVisual3D)); public EulerAngles EulerAngles { get { return (EulerAngles)GetValue(EulerAnglesProperty); } set { SetValue(EulerAnglesProperty, value); } } public static readonly DependencyProperty EulerAnglesProperty = DependencyProperty.Register("EulerAngles", typeof(EulerAngles), typeof(OrbitModelVisual3D)); public Point3D Scale { get { return (Point3D)GetValue(ScaleProperty); } set { SetValue(ScaleProperty, value); } } public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register("Scale", typeof(Point3D), typeof(OrbitModelVisual3D)); public double Longitude { get { return (double)GetValue(LongitudeProperty); } set { SetValue(LongitudeProperty, value); } } public static readonly DependencyProperty LongitudeProperty = DependencyProperty.Register("Longitude", typeof(double), typeof(OrbitModelVisual3D)); public double Latitude { get { return (double)GetValue(LatitudeProperty); } set { SetValue(LatitudeProperty, value); } } public static readonly DependencyProperty LatitudeProperty = DependencyProperty.Register("Latitude", typeof(double), typeof(OrbitModelVisual3D)); public double CourseAngle { get { return (double)GetValue(CourseAngleProperty); } set { SetValue(CourseAngleProperty, value); } } public static readonly DependencyProperty CourseAngleProperty = DependencyProperty.Register("CourseAngle", typeof(double), typeof(OrbitModelVisual3D)); }
Example of using control:
<l:OrbitModelVisual3D Scale="0.005 0.005 0.005" Radius="{Binding OrbitModel.CurrentPosition.Radius}" Longitude="{Binding OrbitModel.StartPoint.Longitude}" Latitude="{Binding OrbitModel.StartPoint.Latitude}" CourseAngle="{Binding OrbitModel.CurrentPosition.OrbitAngle}" OrbitAxis="{Binding OrbitModel.OrbitAxis}"> <t:FileModelVisual3D Source="3dsModels/tdrs_no_ants.3ds"/> </l:OrbitModelVisual3D>
The program compiles, neither errors nor warnings, just the transmitted data is not bandaged, but when I use ScaleX="{Binding Path=Scale.X, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ModelVisual3D}}}
instead of ScaleX="{Binding Scale.X, ElementName=Model}
ScaleX="{Binding Path=Scale.X, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ModelVisual3D}}}
, then everything works.
ScaleX="{Binding Path=Scale.X, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ModelVisual3D}}}
instead ofScaleX="{Binding Scale.X, ElementName=Model}
ScaleX="{Binding Path=Scale.X, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ModelVisual3D}}}
and for the other properties, respectively, then everything works. - Dmitry Anikinx:Name="Model"
writes: "It is impossible to register a duplicate Name" Model "in this area". - Dmitry AnikinModel
. And if you change theModel
to something else? Or maybe you already have theModel
property in theOrbitModelVisual3D
class? - VladD