更改组合框WPF的值时触发ComoBox SelectionChanged事件 [英] ComoBox SelectionChanged event firing when we changing value of combobox WPF

查看:72
本文介绍了更改组合框WPF的值时触发ComoBox SelectionChanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么使用ComoboBox?当我们更改组合框的值时,会触发SelectionChanged事件在WPF中?

why ComoboBox  SelectionChanged event firing when we changed value of combobox  in WPF?

     <ComboBox  Name="onClockComboBox"  Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Width="200" Height="30" StaysOpenOnEdit="True" IsSynchronizedWithCurrentItem="True" OpenDropDownOnFocus="True" 
                                    ItemsSource="{Binding TravelOtherModel.OnClockOptionListCollection,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Center"  
                                    DisplayMemberPath="OptionName" SelectedValuePath="RowNo" IsFilteringEnabled="True" IsEditable="True" Margin="80,3,0,0">
                                    <ie:Interaction.Triggers>
                                            <ie:EventTrigger EventName="SelectionChanged">
                                            <ie:InvokeCommandAction Command="{Binding OnClockComboBoxSelectedItemChangedCommand}" CommandParameter="{Binding ElementName=onClockComboBox}" >
                                                </ie:InvokeCommandAction>
                                            </ie:EventTrigger>
                                        </ie:Interaction.Triggers>
                                    </RadComboBox>

SelectionChanged Event Code is -

     public void OnClockComboBoxSelectedItemChangedCommand_Event(object obj)
        {
            try
            {
                ComboBox onClockComboBox = obj as ComboBox;
                var item = onClockComboBox.SelectedItem as OnClockOption; 
                string s= onClockComboBox.SelectedValue.ToString();
                onClockComboBox.SelectedValue = "0";
            }
            catch (Exception ex)
            {
                
            }
        }


当我们通过下面的代码设置默认的选择"值时,它再次触发选择已更改"事件的原因是什么?


When we set default 'select' value by below code then its again firing selection Changed event why?

 onClockComboBox.SelectedValue = "0";




推荐答案

当ComboBox中的选择更改时,应该引发SelectionChanged事件: https://msdn.microsoft.com/zh-CN/library/system.windows.controls.primitives.selector.selectionchanged(v=vs.110).aspx

The SelectionChanged event is supposed to be raised when the selection in the ComboBox changes: https://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectionchanged(v=vs.110).aspx

但是,请不要在这些论坛中询问有关第三方控件的问题,因为它们仅适用于Microsoft的产品和技术.如果您对Telerik的RadComboBox控件或其任何其他控件有任何疑问或问题,则您 应该在自己的支持论坛中开始新话题: http://www.telerik.com/forums/wpf/combobox .

But please don't ask questions about third-party controls in these forums as they are intended for Microsoft's products and technologies only. If you have any questions or issues regarding Telerik's RadComboBox control or any other of their controls, you should start a new thread in their own support forums: http://www.telerik.com/forums/wpf/combobox.

希望有帮助.

请记住通过将有用的帖子标记为答案来关闭话题,如果您有新问题,请在适当的论坛中开始新话题.请不要在同一线程中问几个问题.

Please remember to close your threads by marking helpful posts as answer and then start a new thread in an appropriate forum if you have a new question. Please don't ask several questions in the same thread.


这篇关于更改组合框WPF的值时触发ComoBox SelectionChanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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