确认在选项卡之间切换

编程入门 行业动态 更新时间:2024-10-28 15:32:57
本文介绍了确认在选项卡之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个选项.用户将输入一些数据并将其保存在第一个选项卡上.第二个选项卡列出了保存的数据.我需要的是,当用户在将数据保存到第一个选项卡中之前选择了第二个选项卡时,将显示一个确认消息框,显示是,否和取消.如果用户单击是"按钮,则应保存数据并转到第二个选项卡.如果他单击否,则无需保存数据,最后,如果单击取消,该选项卡将保留所有输入的数据.我该怎么做?

I have two tabitems. User will enter some data and save it on the first tab. The second tab lists the saved data. What I need is when the user select the second tab before saving data in first tab a confirmation message box with Yes, No and Cancel should be shown. If the user clicks Yes button the data should be saved and go to the second tab. If he hits No, the data need not to be saved and finally if Cancel is hit the tab will retain with all entered data. How can i make this?

推荐答案

为简单起见,您可以在隐藏代码"文件中进行以下操作.

To keep things simple you can do the follwing in the Code Behind file.

我将创建要在WPF控件中显示和编辑的数据的Model类.使模型实现 INotifyPropertyChanged 和 IEditableObject 接口.

I'd create a Model class of the data you want to display and edit in the WPF Control. Make the Model implement the INotifyPropertyChanged and IEditableObject interfaces.

INotifyPropertyChanged 将允许您绑定到模型. IEditableObject 将允许您提供编辑",保存"和取消"功能.

INotifyPropertyChanged will allow you to Bind to the Model. IEditableObject will allow you to provide Edit, Save and Cancel functionality.

TabControl具有一个您可以处理的 SelectionChanged 事件,该事件可让您检测用户何时更改选项卡,在此处理程序中,您可以使用 System.Windows.MessageBox 要求用户保存等, System.Windows.MessageBox.Show()返回一个 MessageBoxResult 对象,您可以使用该对象确定用户单击了什么按钮并执行适当的操作

The TabControl has a SelectionChanged Event you can handle, that will allow you to detect when the user changes tabs, in this handler you can use System.Windows.MessageBox to ask the user to save etc, System.Windows.MessageBox.Show() returns a MessageBoxResult Object you can use to detirmine what button the user clicked and perform the appropiate action.

这不是完成任务的好方法,但是它使事情变得简单,您可能需要研究一些WPF设计模式以帮助实现代码可管理性.

This is not a geat way to do things, but it keeps things simple, you may want to look into some WPF design Patterns to help with Code Manageability.

如果您需要进一步说明,请询问.

If you need anything explained further, just ask.

更多推荐

确认在选项卡之间切换

本文发布于:2023-11-27 20:45:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!