我的任务是为应用程序创建一个3D界面。在查看了我的选项之后,我认为Viewport2DVisual3D是最容易理解和使用我的游戏设计背景(我对矩阵变换等感到满意)。
到目前为止,我已经在屏幕上显示了一个半圆形“舞台”模式的按钮列表。这是一个好的开始。现在,我想要做的是让旋转木马随用户输入旋转。现在,点击时我会有一个按钮旋转到中心视图,但最终我会使用操作数据来刷屏幕。
我遇到的问题是将每个V2DV3D的Transform属性绑定到支持每个Button控件的数据。我不知道如何在代码隐藏中执行此操作,并且需要进行代码隐藏才能以编程方式构建转换。
实际上,我以这种方式分配值(vv
是Viewport2DVisual3D
对象):
vv.SetValue(Viewport2DVisual3D.TransformProperty, item.Transform);
其中item
是实现CarouselItem
的{{1}}:
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
,新值 与旧版
所以最初的'绑定'工作正常,按钮进行初始转换,但对Transform的任何进一步修改都没有变化。 Transform属性更改事件的事件处理程序没有订阅者。我应该如何更改与CarouselItem和V2DV3D的绑定/关系以使它们链接?似乎没有任何类型的DataContext或V2DV3D的类似属性我可以将整个对象绑定到。