组合框 MVVM silverlight 消息框
我正在 Silverlight MVVM 模型中工作。面临一个小问题:
有一个组合框显示两个值(默认选择其中一个),当用户更改组合框的值时,会显示一个消息框,要求用户确认,如果“是”则显示值将被更改,如果“否”,则值保持不变,消息框保留在 ViewModel 中,并在所选项目的设置属性上触发。我面临的问题是,当用户选择“否”(或取消)时,即使没有任何反应(根据功能),但组合框不会返回到原始位置,并且仍保留在所选位置(即组合框保持在展开位置) 。
为什么它停留在那个展开的位置以及如何将其恢复到原来的位置?
这是代码的一部分,希望这有助于理解:
MessageBoxResult msg = MessageBox.Show("Really delete?","Confirm delete", MessageBoxButtons.OKCancel)
if(msg == "OK")
{
Do this;
}
else
{
Do nothing;
}
现在组合框中有两个值,即“A”和“A”。 'B'。当用户更改值时,即如果默认值为 A 并且用户将其更改为 B,则弹出窗口将询问您是否要继续,当用户单击“确定”时,一切正常,但当用户单击“取消”时,将出现此弹出窗口尽管应用程序中没有任何反应,但 UI 中的值发生了更改,即用户已取消将值从 A 更改为 B,但随后 B 也会作为选定项显示在组合框中。
I am working in Silverlight MVVM model. Facing a small problem:
There is a combobox which displays two values(One of them is selected by default) when the User changes the value of the combobox a messagebox is displayed which asks for the confirmation of the User, if "yes" then the value will be changed and if "no" then value be remain the same, the messagebox is kept in the ViewModel and is fired on selected Item's set property. The problem i am facing is that when the user selects No(Or Cancel) even though nothing happens(as per the functionality) but the combobox doesnot go back to original position and it remains in the selected posistion(i.e. combobox remain in expanded position).
Why is it staying in that expanded position and how to take it to it's original position??
Here is some part of the code hope this helps understanding :
MessageBoxResult msg = MessageBox.Show("Really delete?","Confirm delete", MessageBoxButtons.OKCancel)
if(msg == "OK")
{
Do this;
}
else
{
Do nothing;
}
Now there are two values in the Combobox say 'A' & 'B'. This popup will comeup when user changes the value i.e. if the default value is A and user changes it to B then the popup will ask whether u want to continue or not, when user clicked on OK everything works fine but when user clicks on Cancel even though nothing happens in the application the Value gets changed in the UI i.e. the User has said Cancel to the change of value from A to B but then also B is displayed in the combobox as selected item.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将组合框的 SelectedItem 值重置回原始值。
原因是 ComboBox 中的值的绑定发生在 SelectedItem 更改事件之前。这意味着即使在显示消息之前,应用程序也已经更改了组合框的值。如果您需要 ComboBox 显示原始值,则需要在代码中将其重置回。
You need to reset the SelectedItem value of the combo box back to the original value.
The reason is that the binding of the value in the ComboBox occurs before the SelectedItem change event. This means the value for your combox has already been altered by the application even before the message is displayed. If you need the ComboBox to display the original value you need to reset it back in the code.