WPF 仪表板和小部件
你好,我想写一些仪表板。您应该能够从某个来源拖动仪表板上的小部件。小部件的布局应该是自由的(首先是画布,后来是一些自己的面板)。
我的问题:
- 对于有关此类控件的信息,您有什么提示吗?
- 使用 Selector 作为 BaseClass 是一个好主意还是应该从 Control 继承
Hi I would like to write some kind of dashboard. You should be able to drag widgets on the dashboard from some source. The layout of the widgets should be free (first Canvas, later some own Panel).
My questions:
- Do you have any hints for information about this kind of controls for me?
- Is it a good idea to use Selector as BaseClass or should inherit from Control
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将为所有小部件创建一个
BaseClass
,然后为每个小部件构建一个继承该BaseClass
的ViewModel
以及一个View
与该ViewModel
一起使用之后,我会得到类似
ObservableCollection的东西。在主应用程序
,并将其绑定到ViewModel
中打开 WidgetsItemsControl
。ItemsControl
会将其ItemsPanelTemplate
设置为Canvas
,并且每个WidgetBaseViewModel
将包含一个Top< /code>、
Left
、Height
和Width
属性。显示每个小部件的实际 UI 将基于
DataTemplate
,并且可以是您想要的任何内容,尽管UserControl
是最简单的此外,您还需要绑定您的
Canvas.Top
/Canvas.Left
位于ItemContainerStyle
上,而不是实际的ItemTemplate
上以使其显示正确地在画布上。I would make a
BaseClass
for all widgets, and then build aViewModel
that inherits from thatBaseClass
for each Widget, along with aView
to go with thatViewModel
After that, I would have something like
ObservableCollection<WidgetBaseViewModel> OpenWidgets
in the main applicationViewModel
, and bind it to anItemsControl
.The
ItemsControl
would have it'sItemsPanelTemplate
set to aCanvas
, and eachWidgetBaseViewModel
would contain aTop
,Left
,Height
, andWidth
property.The actual UI to display each Widget with would be based on a
DataTemplate
, and could be anything you want, although aUserControl
would be easiestAlso, you'll need to bind your
Canvas.Top
/Canvas.Left
on theItemContainerStyle
instead of on the actualItemTemplate
to get it to display correctly in the canvas.