相机位置的数据绑定问题 [英] Problem with data binding for camera position

查看:58
本文介绍了相机位置的数据绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我对WPF不太了解,所以我不了解很多事情,现在面临的问题是我的应用程序中有三个滑块,一旦滑块改变了相机的位置,我就需要改变它的位置,滑块在不同的xamls中,而相机设置在另一个xaml中.我已经为x,y,z坐标定义了依赖项属性:

Hi,since i''m too fresh in wpf i dont know lots of things and the problem now im facing is that i have three sliders in my application and what i need is once the sliders change the position my camera also changes its position,sliders are in different xamls and camera settings are in another xaml.I''ve already defined dependency property for x,y,z coordination:

<local:Panel3D
              corX="{Binding Value,  ElementName=EditorX}"
              corY="{Binding Value,  ElementName=EditorY}"
              corZ="{Binding Value,  ElementName=EditorZ}"


编辑器x,y是我的sliders.现在在另一个xaml中,我想在那里使用cor x,y,z作为相机位置的协调,但我不知道该怎么做


editor x,y, are my sliders.now in another xaml i want to use there cor x,y,z as coordination of my camera position but i dont know how to do that

<Viewport3D.Camera>
        <PerspectiveCamera

          LookDirection="0,0,-10"

          Position=???

          UpDirection="0,10,0"

          />
    </Viewport3D.Camera


>

如果有人给我一些指导,我将不胜感激.


>

if anyone gives me some guidelines i would really appreciate it,thank you.

推荐答案

在Panel3D控件中,由于X,Y, Z可以通过创建另一个Point3D类型的依赖属性并将其绑定到PerspectiveCamera的Position属性来实现要求,如下所示.

In the Panel3D control, since you have 3 dp''s for X, Y, Z you can achieve the required by creating one more dependancy property of type Point3D and bind it to the Position property of the PerspectiveCamera, like below.

<Viewport3D.Camera>
        <PerspectiveCamera
          LookDirection="0,0,-10"
          Position={Binding Calculated3DPoint}
          UpDirection="0,10,0"
          />
</Viewport3D.Camera




在每个依赖项属性的回调中,计算更新像这样的Caluclated3DPoint属性.




In the callback of each dependancy property calculate update the Caluclated3DPoint property like.

#region Properties

        public double CorX
        {
            get { return (double)GetValue(CorXProperty); }
            set { SetValue(CorXProperty, value); }
        }

        public double CorY
        {
            get { return (double)GetValue(CorYProperty); }
            set { SetValue(CorYProperty, value); }
        }

        public double CorZ
        {
            get { return (double)GetValue(CorZProperty); }
            set { SetValue(CorZProperty, value); }
        }

        public Point3D Calculated3DPoint
        {
            get { return (Point3D)GetValue(Calculated3DPointProperty); }
            set { SetValue(Calculated3DPointProperty, value); }
        }

        #endregion

        #region Dependency Properties

        public static readonly DependencyProperty CorXProperty =
            DependencyProperty.Register("CorX", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0d, (dependencyObject, e) =>
            {
                var v = (MainWindow)dependencyObject;

                if (v != null)
                {
                    v.Calculated3DPoint = new Point3D((double)e.NewValue, v.CorY, v.CorZ);
                }
            }));

        public static readonly DependencyProperty CorYProperty =
            DependencyProperty.Register("CorY", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0d, (dependencyObject, e) =>
            {
                var v = (MainWindow)dependencyObject;

                if (v != null)
                {
                    v.Calculated3DPoint = new Point3D(v.CorX, (double)e.NewValue, v.CorZ);
                }
            }));

        public static readonly DependencyProperty CorZProperty =
            DependencyProperty.Register("CorZ", typeof(double), typeof(MainWindow), new UIPropertyMetadata(0d, (dependencyObject, e) =>
            {
                var v = (MainWindow)dependencyObject;

                if (v != null)
                {
                    v.Calculated3DPoint = new Point3D(v.CorX, v.CorY, (double)e.NewValue);
                }
            }));

        public static readonly DependencyProperty Calculated3DPointProperty =
            DependencyProperty.Register("Calculated3DPoint", typeof(Point3D), typeof(MainWindow), new UIPropertyMetadata(new Point3D()));

        #endregion



HTH



HTH


这篇关于相机位置的数据绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆