开发者

Can I bind two methods to a WPF Control?

开发者 https://www.devze.com 2023-01-16 01:26 出处:网络
I have this combo box <ComboBox Height=\"23\" SelectionChanged=\"comboBox1_SelectionChanged\"> <ComboBoxItem Content=\"Opt1\"/>

I have this combo box

    <ComboBox Height="23"
              SelectionChanged="comboBox1_SelectionChanged">
        <ComboBoxItem Content="Opt1"/>
        <ComboBoxItem Content="Opt2"/>
    </ComboBox>

Basically what I need is to 开发者_如何转开发run two methods, the one already bound (combobox1_SelectionChanged) and an additional one I created. Is this possible?


I would probably just bind to 1 function and have that function call the common pieces of code.


Yes, but you can't do this declaratively. Use the += operator in C#.

MyComboBox.SelectionChanged += new SelectionChangedEventHandler(method1);
MyComboBox.SelectionChanged += new SelectionChangedEventHandler(method2);
...
0

精彩评论

暂无评论...
验证码 换一张
取 消