防止在 Silverlight 中选择 TabControl
有什么方法可以防止 Silverlight 4 中 TabControl 中的选项卡发生更改吗?
一个简单的情况是,当我有一个包含一些数据的表单时,我想询问用户他/她是否想在实际更改选项卡之前保存这些数据。
我见过有关如何在 WPF 中执行此操作的代码示例,但在 Silverlight 中却没有。
我该怎么做才能阻止选项卡发生变化?
Is there any way to prevent the change of a tab in TabControl in Silverlight 4?
A simple case is when I've got a form with some data, and I want to ask the user if he/she wants to save this data before actually changing the tab.
I've seen code examples on how to do this in WPF, but not in Silverlight.
What can I do to stop the tab from changing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 SelectedIndex 绑定到数据上下文上的属性。
在 SET 访问器中,编写代码来检查用户是否确实想要执行他们想要执行的操作。
最终效果是,如果用户在对话框中选择“取消”,则私有变量永远不会更改 - PropertyChanged 事件触发,将所选索引重新绑定到现有值。
希望这就是您想要实现的目标。
更新 (11/10/2012) - 替代方法(可能适用于 SL5?)。在后面编写代码以绑定到 TabControl 的 SelectionChanged 事件,根据您的测试重置选项卡控件的选定项属性。
Bind SelectedIndex to a property on your data context.
In the SET accessor, write your code to check whether the user really wants to do what they're trying to do.
Net effect is, if the user chooses 'cancel' on the dialogue the private variable is never changed - the PropertyChanged event fires, rebinding the selected index to the existing value.
Hope this is what you were trying to accomplish.
UPDATE (11/10/2012) - Alternate method (possibly for SL5?). Write code behind to tie into SelectionChanged event of your TabControl, reset the tab control's selected item property based on your test.