如何在Windows之间同步ComboBox [英] How to sychronize ComboBoxes between Windows

查看:109
本文介绍了如何在Windows之间同步ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个wpf窗口,每个窗口都有相同的ComboBox,名为cboSources。 我希望两个ComboBox同步,也就是说,当用户在一个窗口中更改选择时,另一个窗口中的选择也将是相同的。 
无论用户点击哪个窗口,这都应该有效。



我试图创建自己的事件,当cboSoources.SelectionChanged时会引发事件被解雇。 我可以创建事件和自定义EventArgs类,但我无法弄清楚如何将它们连接起来以使它们工作。



我也试过创建一个从cboSoources.SelectionChanged子例程中调用的每个窗口中的Sub都会更改另一个窗口中的SelectedItem,但我无法弄清楚如何引用其他例程的实例。



这里没有代码,因为我不想创建XY问题,但我确实想要了解我尝试过的内容。



建议?

解决方案

由于WPF有一个论坛我在那里提出你的问题。


有一个想法,如果两者都有Windows共享相同的DataContext,这将是一个正确方向的开始,加上&absp; IsSynchronizedWithCurrentItem


I've got two wpf windows that each have identical ComboBoxes named cboSources.  I want to the two ComboBoxes to be sychronized, that is, when the user changes the selection in one window, the selection in the other window will also be the same.  This should work no matter which window the user clicks in.

I've tried to create my own event that would be raised when the cboSoources.SelectionChanged event is fired.  I can create the event and the custom EventArgs class but I cannot figure out how to wire them all together to make them work.

I've also tried just creating a Sub in each window that is called from the cboSoources.SelectionChanged subroutine that changes the SelectedItem in the other window but I cannot figure out how to reference the instance of the other routine.

There's no code here because I don't want to create the XY Problem but I did want to relate what I've tried.

Suggestions?

解决方案

Since there is a forum for WPF I'm moving your question there.

There is one thought, if both windows share the same DataContext this would be a start in the right direction coupled with IsSynchronizedWithCurrentItem.


这篇关于如何在Windows之间同步ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆