允许对象移动的 WPF 容器
我使用过一些 WPF,但它使用复制粘贴来实现 XAML,并且主要使用 C# 编码来实现后台逻辑。现在我想与朋友一起启动一个项目并使用 WPF,因为它将是一个 GUI 密集型项目。
问题:
在我们的应用程序中,我们希望有一个可以放置对象的表面,并且用户应该能够移动对象。这应该是二维的。我所说的移动是指单击一个对象并将其在表面内拖动。最后,我认为移动应该只在一个方向(仅水平),但目前应该可以向任何方向移动它们。唯一应该适用的限制是它们不能保持一个在另一个之上。
您能否给我一些提示,告诉我我们应该为表面使用什么容器,我们应该为容器中移动的对象使用什么基类?或者 WPF 是否有一些开箱即用的东西可以用于这种情况?我们应该如何开始的一般提示将不胜感激。
我知道这对于那些没有太多 WPF 经验的人来说意义重大,但当我从 C++ 转到 C# 时,我也做了同样的事情,而且它有效:)。
I worked a litte with WPF but it used copy-paste for XAML and mostly C# coding for the background logic. Now I want to start a project with a friend and use WPF because it will be a GUI intensive one.
Question:
In our app, we want to have a surface on which we can put objects and the user should be able to move the objects around. This should be 2D. By moving, I mean click on an object and drag it around inside the surface. In the end, I think the movement should be only in one direction ( only horizontal), but for the moment it should be possible to move them in any direction. The only restriction that should apply is that they can't remain one on top of the other.
Can you give me any hints on what container should we use for the surface, what base class should we use for the objects moving in the container? Or does WPF have something that works out of the box for this case? General hints how we should start this would be appreciated.
I know that this is a lot for some one that doesn't have so much experience with WPF but I did the same thing when I came from C++ to C# and it worked :).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Canvas 始终是移动事物的好容器。
Canvas is always a good container to move things around.
查看 CodeProject 上的这篇文章:
WPF 图表设计器:第 1 部分
它使用一个
Canvas
来显示项目,并实现代码以允许项目在Canvas
周围拖动。Have a look at this article on CodeProject:
WPF Diagram Designer: Part 1
It uses a
Canvas
to display items, and implements code to allow the items to be dragged around theCanvas
.这是 .NET 3.5 版本的博文
http://mtaulty.com/CommunityServer /blogs/mike_taultys_blog/archive/2009/05/08/test-post-1.aspx
“可拖动”是讨论 表达式混合中的行为。
This is a blogpost from version .NET 3.5
http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/05/08/test-post-1.aspx
"Dragable" is a common case when discussing the topic of behavior in expression blend.