是否可以将带有绑定的 Transform3DGroup 放入资源字典中?
我正在尝试创建一个 3D 场景来以图形方式表示我的模型。 我的模型包含 N 个对象(objA,objB,...),每个对象都派生自一个抽象类,该抽象类具有一些属性,例如 Position、With、Height、Length 等
目前我的 Viewport3D 是这样完成的:
<Viewport3D>
...
<ModelVisual3D Content="{StaticResource objAView}">
<ModelVisual3D.Transform>
<Transform3DGroup>
<ScaleTransform3D ScaleX="{Binding Path=objA.Width}" ScaleY="{Binding Path=objA.Height}" ScaleZ="{Binding Path=objA.Length}"/>
<TranslateTransform3D OffsetX="{Binding Path=objA.Position.X}" OffsetY="{Binding Path=objA.Position.Y}" OffsetZ="{Binding Path=objA.Position.Z}"/>
</Transform3DGroup>
</ModelVisual3D.Transform>
</ModelVisual3D>
<ModelVisual3D Content="{StaticResource objBView}">
<ModelVisual3D.Transform>
<Transform3DGroup>
<ScaleTransform3D ScaleX="{Binding Path=objB.Width}" ScaleY="{Binding Path=objB.Height}" ScaleZ="{Binding Path=objB.Length}"/>
<TranslateTransform3D OffsetX="{Binding Path=objB.Position.X}" OffsetY="{Binding Path=objB.Position.Y}" OffsetZ="{Binding Path=objB.Position.Z}"/>
</Transform3DGroup>
</ModelVisual3D.Transform>
</ModelVisual3D>
...
</Viewport3D>
是否可以避免为每个 ModelVisual3D 重写 Transform3DGroup ,因为它们几乎相同?
谢谢
I'm trying to create a 3d scene to represent graphically my model.
My model contains N objects (objA, objB, ...) each of them derive from an abstract class that has some property like Position,With,Height,Length etc
At the moment my Viewport3D is done in this way:
<Viewport3D>
...
<ModelVisual3D Content="{StaticResource objAView}">
<ModelVisual3D.Transform>
<Transform3DGroup>
<ScaleTransform3D ScaleX="{Binding Path=objA.Width}" ScaleY="{Binding Path=objA.Height}" ScaleZ="{Binding Path=objA.Length}"/>
<TranslateTransform3D OffsetX="{Binding Path=objA.Position.X}" OffsetY="{Binding Path=objA.Position.Y}" OffsetZ="{Binding Path=objA.Position.Z}"/>
</Transform3DGroup>
</ModelVisual3D.Transform>
</ModelVisual3D>
<ModelVisual3D Content="{StaticResource objBView}">
<ModelVisual3D.Transform>
<Transform3DGroup>
<ScaleTransform3D ScaleX="{Binding Path=objB.Width}" ScaleY="{Binding Path=objB.Height}" ScaleZ="{Binding Path=objB.Length}"/>
<TranslateTransform3D OffsetX="{Binding Path=objB.Position.X}" OffsetY="{Binding Path=objB.Position.Y}" OffsetZ="{Binding Path=objB.Position.Z}"/>
</Transform3DGroup>
</ModelVisual3D.Transform>
</ModelVisual3D>
...
</Viewport3D>
Is it possible to avoid to rewrite the Transform3DGroup for each ModelVisual3D giving that they are almost the same?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有办法按照您的标题建议的方式使用资源来完成此操作,因为您只能指定一次绑定。
但是,您可以编写一个派生自 Transform3DGroup 的类,并采用 objA 和 obB 的单个绑定。因此,您可以在代码中使用类似的内容:
然后在自定义类中,您可以使用 ObjectToBindAgainst 来设置所包含转换的所有其他部分。
如果你真的只做两次,它并不能为你节省很多,但如果你做了很多次,它可能是值得的。
I don't think that there's a way to do it with resources the way your title suggests, because you'd only be able to specify the binding once.
However, you could write a class that derives from
Transform3DGroup
and takes a single binding of whatever the objA and obB are. So you could have something like this in your code instead:And then in your custom class you can use the ObjectToBindAgainst to set all the other pieces of the included transforms.
It doesn't save you a whole lot if you're really just doing this twice, but if you're doing it many times, it might be worth it.