WPF 中的绑定更新顺序由什么定义?
我有一段使用多个绑定的 WPF/C# 代码:
- 组合框用于选择帐户
- 第二个组合框的 itemssource 属性绑定到所选帐户。 第二个组合框用于选择联系人。
- 网格的 itemssource 属性绑定到所选帐户。 该网格包含选定的帐户发票。
- 联系人组合框父 DataContext 绑定到选定的发票。
- 联系人组合框的 SelectedItem 绑定到数据上下文中发票的 InvoiceContact 属性。
但是,绑定并未按照我希望的顺序更新。 当我选择另一个帐户时,“联系人”组合框的“ItemsSource”属性首先发生变化,然后它显然会更改“SelectedItem”,这会更改“InvoiceContact”,然后,选定的“发票”会发生变化...
无需说明它会弄乱所选的“发票” 。
如何控制更新绑定的顺序?
谢谢
亚历克斯
I have a piece of WPF/C# code that uses several Bindings:
- A combobox is used to select an Account
- The itemssource property of a second combobox is bound to the selected Account. This second combobox is used to select a Contact
- The itemssource property of a grid is bound to the selected Account. This grid contains the selected Account Invoices.
- The Contacts combobox parent DataContext is bound to the selected Invoice.
- The SelectedItem of the Contacts combobox is bound to the InvoiceContact property of the Invoice in the datacontext.
However the bindings are not updated in the order I want them to be. When I select another Account, the ItemsSource property of the Contact combobox change first, then it obviously change the SelectedItem, which changes the InvoiceContact and THEN, the selected Invoice changes...
No need to tell that it messes up the Invoice that was selected.
How can I control the order used to update the Bindings?
Thanks
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否在类中实现 INotifyPropertyChanged 接口? 我认为如果你正常实现 INotifyPropertyChanged ,顺序并不那么重要
Are you implementing INotifyPropertyChanged interface in your classes? I think the order is not so important if you implement INotifyPropertyChanged normally
当我正要写一个答案(带有 PropertyChanged 的东西......)时,我意识到:
我不知道你在尝试什么。
所以我画了你的描述...
我真的不知道你在步骤 4 和 5 中尝试了什么。也许你可以详细说明一下?
As I was about to write an answer (something with PropertyChanged...) I realized:
I don't have a clue on what you're trying.
So I painted your description...
I really don't know what your trying in steps 4 and 5. Maybe you could elaborate ?