WPF 控件分组
我有一组控件,如下所示: <图片链接> 我重复使用了很多次。它非常简单,一个列表视图、3 个按钮和一些布局面板。
我想将其变成可重用的组件,但列表视图中的列可以更改,并且它们绑定的源也会更改。
我该怎么办?我已经看过 ContentTemplates 和 UserControls 等之间的许多比较,但它们似乎从来没有起作用(例如,添加将引发一个事件,我必须处理该事件才能将某些内容添加到列表视图,删除将引发一个我可能会问的事件如果他们首先确定的话)。
我已经使用自己的 UserControl 完成了这些事件,但无法将 GridViewColumns 列表传递给该控件。这也意味着我必须从 UserControl 手动公开 SelectedItem 等。子类化 Listview 似乎有利于设置和访问,但从概念上讲,在列表视图区域中拥有其他控件似乎并不正确。
正确的方法是什么?
I have a group of controls that look like this:
<Link to Image>
that i reuse a number of times. It's really simple a listview, 3 buttons and some layout panels.
I want to turn this into a reusable component but the columns in the listview can change and the sources they are bound to will change.
How do i go about this? i've seen many comparisons between ContentTemplates and UserControls etc but they never seem to be functional (eg Add will raise an event which i'll have to handle to add something to the listview, remove will raise an event where i'll likely ask if they are sure first).
I've accomplished the events with my own UserControl, but can't pass a list of GridViewColumns to the control. It also means i have to expose SelectedItem etc manually from the UserControl. Subclassing Listview seems promising for setup and access but doesn't conceptually seem right to have other controls in the listview area.
What is the right way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我肯定会推荐 UserControl。您应该:
I would definately recommend a UserControl. You should: