在 WPF 中重用按钮
我有一堆不同的对象,通常使用不同的 DataTemplate 在同一个 TabControl 中编辑,但我希望每个 DataTemplate 具有共同的外观和感觉,每个选项卡右下角的“确定”和“取消”按钮将关闭选项卡或保存内容,然后关闭当前选定的选项卡。在每个选项卡上放置按钮的最佳方式是什么?有没有一种方法可以做到这一点,而无需在我的所有数据模板中复制和粘贴按钮和堆栈面板?
I have a bunch of different objects that are commonly edited in the same TabControl using different DataTemplates, but I want each DataTemplate to have a common look and feel with Ok and Cancel buttons at the bottom right of each tab that will close the tab or save the content and then close the currently selected tab. What's the best way to place buttons on each tab ? Is there a way to do it without copying and pasting the buttons and stack panel across all of my data templates ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然,您可以创建自己的
OkCancelSaveControl
。在 WPF 中,创建“用户控件”比听起来容易得多。 这是一个教程。简而言之,您OkClick
),以防某些选项卡需要特殊处理。Sure, you can create your own
OkCancelSaveControl
. In WPF, creating a "user control" is much easier than it sounds. Here is a tutorial. In a nutshell, youOkClick
), in case some tab requires special treatment.我将制作一个自定义控件,我们将其称为 MyCoolTabItem,它继承自 TabItem 类,然后将按钮放入该控件中。然后只需将 MyCoolTabItem 而不是 TabItem 添加到所有 TabControls 中,它就会包含所有按钮。
I would make a custom control, lets call it MyCoolTabItem, that inherits from the TabItem class, and just throw your buttons into the control. Then just add a MyCoolTabItem instead of a TabItem to all of your TabControls and it will have all of your buttons on it.
您可以创建一个包含这些按钮的基本视图类。需要按钮的视图将继承它们和通用功能。
You could make a base view class that held those buttons. Views that needed the buttons would inherit them and common functionality.