Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void AddDoubleClickEventStyle(ListBox listBox, MouseButtonEventHandler mouseButtonEventHandler)
- {
- if (listBox.ItemContainerStyle == null)
- listBox.ItemContainerStyle = new Style(typeof(ListBoxItem));
- listBox.ItemContainerStyle.Setters.Add(new EventSetter()
- {
- Event = MouseDoubleClickEvent,
- Handler = mouseButtonEventHandler
- });
- }
- //Usage:
- AddDoubleClickEventStyle(listView1, new MouseButtonEventHandler(listView1_MouseDoubleClick));
- EventManager.RegisterClassHandler(typeof(ListBoxItem),
- ListBoxItem.MouseLeftButtonDownEvent,
- new RoutedEventHandler(this.MouseLeftButtonDownClassHandler));
- private void OnMouseLeftButtonDown(object sender, RoutedEventArgs e)
- {
- }
- <ListBox Name="testListBox">
- <ListBox.ItemContainerStyle>
- <Style TargetType="{x:Type ListBoxItem}">
- <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBox_MouseLeftButtonDown" />
- </Style>
- </ListBox.ItemContainerStyle>
- </ListBox>
- myListBox.AddHandler(UIElement.MouseDownEvent,
- new MouseButtonEventHandler(ListBox_MouseDown), true);
- <ListBox PreviewMouseDown="PlaceholdersListBox_OnPreviewMouseDown"/>
- private void PlaceholdersListBox_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
- {
- var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;
- if (item != null)
- {
- // ListBox item clicked - do some cool things here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement