WPF ListBox as RadioButtonList - 通过 WPF 验证模拟 SelectionChanging 事件
我使用 ListBox 来实现 RadioButtonList 行为(这是人们推荐的,因为 WPF 中没有固有的单选按钮列表)。列表框绑定到 ViewModel。
现在,每当用户更改列表框中的选择时,我想检查用户在屏幕部分是否有一些未保存的数据并相应地提示(通常是,否,取消)。如果我使用 SelectionChanged 事件,则选择已经发生,因此提示是没有用的。而且似乎没有任何 SelectionChanging 事件。
我不确定,但我可以通过使用 WPF 绑定验证规则来模拟 SelectionChanging 行为吗? 或者我应该使用 MouseButtonDown 事件?这会导致问题吗?
I am using ListBox for having RadioButtonList behaviour (that's what people recommend as there is no inherent radio button list in WPF). The listbox is bound to a ViewModel.
Now, whenever user changes the selection on listbox, I want to check whether user has some unsaved data on the part of screen and prompt accordingly (typical yes,no,cancel). If I use SelectionChanged event, the selection has already occured and hence, prompting is of no use. And there doesn't seem to be any SelectionChanging event.
I am am not sure but can I mimic SelectionChanging behaviour by using WPF binding validation rules?
Or should I use MouseButtonDown event? Would that lead to problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要将它们放在列表框中,它们可以像这样分组:
注意 GroupName,它将集合放在一起,至于您问题的其余部分,我在理解您需要什么时遇到了一个小问题,抱歉: (
You don't need to put them in a listbox, the are group-able like so:
Notice the GroupName, this holds the collection together, as for the rest of your question I am having a slight issue understanding what you need, sorry :(