Current filter:
                                You should refresh the page.
                                  • Hello,
                                    I am using a ListBoxEdit. I have the ItemsSource bound to an observableCollections of type "Myobject".
                                    When the user double clicks on an item in the list box, how can I get the underlying object of the item clicked  in the event handler?
                                     in other words how do I get Myobject x from the arguments?
                                           private void FileListbox_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
                                            {
                                                Myobject  x  = ??
                                             }

                                    Thank you.

                                1 Solution

                                Creation Date Importance Sort by

                                Hello,

                                I see the following ways to accomplish your task.

                                1. Handle the MouseDoubleClick event for list box items directly. As well as in the standard ListBox, you can subscribe to it in a custom ItemContainerStyle. For example:
                                [XAML]
                                <dxe:ListBoxEdit ItemsSource="{Binding Items}"> <dxe:ListBoxEdit.ItemContainerStyle> <Style TargetType="dxe:ListBoxEditItem"> <EventSetter Event="MouseDoubleClick" Handler="ListBoxEditItem_MouseDoubleClick" /> </Style> </dxe:ListBoxEdit.ItemContainerStyle> </dxe:ListBoxEdit>

                                This way, you can obtain the clicked item from the sender object.

                                [C#]
                                private void ListBoxEditItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var listBoxEditItem = (ListBoxEditItem)sender; var item = listBoxEditItem.Content; //... }
                                2. Obtain the clicked item from the visual tree. For example, you can do this using our LayoutTreeHelper class.
                                [C#]
                                private void ListBoxEdit_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var listBoxEditItem = LayoutTreeHelper.GetVisualParents((DependencyObject)e.OriginalSource).OfType<ListBoxEditItem>().FirstOrDefault(); if (listBoxEditItem == null) return; var item = listBoxEditItem.Content; //... }

                                Thanks

                                • Customer61282 10.15.2019

                                  Hi Ivan,
                                  This works. The solution is not very obvious you must admit. I would have never figured it out on my own.

                                  Thank you very much for your help.
                                  Kam