WPF ListBox as RadioButtonList - 通过 WPF 验证模拟 SelectionChanging 事件

发布于 2024-08-17 03:33:19 字数 323 浏览 6 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北风几吹夏 2024-08-24 03:33:19

您不需要将它们放在列表框中,它们可以像这样分组:

 <RadioButton GroupName=“One“ IsChecked=“True“/> 

注意 GroupName,它将集合放在一起,至于您问题的其余部分,我在理解您需要什么时遇到了一个小问题,抱歉: (

You don't need to put them in a listbox, the are group-able like so:

 <RadioButton GroupName=“One“ IsChecked=“True“/> 

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 :(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文