1

我的任务是为应用程序创建某种 3D 界面。在查看了我的选项后,我认为 Viewport2DVisual3D 是最容易理解和使用我的游戏设计背景的(我对矩阵转换等感到满意)。

到目前为止,我已经有一个很好的按钮列表,在屏幕上以半圆形“舞台”模式显示。这是一个好的开始。现在,我想做的是让轮播随着用户输入而旋转。现在,我会在单击时将按钮旋转到中心视图,但最终我将使用操作数据来允许屏幕滑动。

我遇到的问题是将每个 V2DV3D 的 Transform 属性绑定到支持每个 Button 控件的数据。我不确定如何在代码隐藏中执行此操作,并且它需要代码隐藏才能以编程方式构建转换。

实际上,我以这种方式分配值(vv是一个Viewport2DVisual3D对象):

vv.SetValue(Viewport2DVisual3D.TransformProperty, item.Transform);

itema which在哪里CarouselItem实现INotifyPropertyChanged

public class CarouselItem : INotifyPropertyChanged
{
    [...]

    public Transform3DGroup Transform
    {
        get { return _transform; }
        set { _transform = value; OnPropertyChanged("Transform"); }
    }

    [...]

    private void Recalc()
    {
        Transform3D rotate = new RotateTransform3D(new 
            AxisAngleRotation3D(CarouselBrowser.Up, angle));
        Transform3D translate = new TranslateTransform3D(0, 0,
            CarouselBrowser.Radius);
        Transform3D translate2 = new TranslateTransform3D(
            CarouselBrowser.Focus);
        Transform3DGroup tGroup = new Transform3DGroup();
        tGroup.Children.Add(translate);
        tGroup.Children.Add(rotate);
        tGroup.Children.Add(translate2);
        Transform = tGroup;
    }

    [...]

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propertyName)
    {
        this.VerifyPropertyName(propertyName);
        PropertyChangedEventHandler handler = this.PropertyChanged;
        if (handler != null)
        {
            var e = new PropertyChangedEventArgs(propertyName);
            handler(this, e);
        }
    }
    /// <summary>
    /// Warns the developer if this object does not have
    /// a public property with the specified name. This 
    /// method does not exist in a Release build.
    /// </summary>
    [Conditional("DEBUG")]
    [DebuggerStepThrough]
    public void VerifyPropertyName(string propertyName)
    {
        // Verify that the property name matches a real,  
        // public, instance property on this object.
        if (TypeDescriptor.GetProperties(this)[propertyName] == null)
        {
            string msg = "Invalid property name: " + propertyName;

            if (this.ThrowOnInvalidPropertyName)
                throw new Exception(msg);
            else
                Debug.Fail(msg);
        }
    }
    /// <summary>
    /// Returns whether an exception is thrown, or if a Debug.Fail() is used
    /// when an invalid property name is passed to the VerifyPropertyName method.
    /// The default value is false, but subclasses used by unit tests might 
    /// override this property's getter to return true.
    /// </summary>
    protected virtual bool ThrowOnInvalidPropertyName { get; private set; }

    [...]
}

(部分代码省略;更改Recalc时调用,新值与旧不同)angle

所以最初的“绑定”工作正常,按钮进行初始转换,但对 Transform 的任何进一步修改都不会导致任何变化。Transform 属性更改事件的事件处理程序没有订阅者。我应该如何更改与 CarouselItem 和 V2DV3D 的绑定/关系以使它们链接?似乎没有任何类型的 DataContext 或 V2DV3D 的类似属性可以将整个对象绑定到。

4

0 回答 0