DataGrid.LoadingRow event firing three times - silverlight

I have a HyperLinkButton in every row of a datagrid in my silverlight app. I need to fire an event so I am adding a handler to the click event of the HyperLinkButton in the DataGrid.LoadingRow event. The problem is the event is firing three times (more accurately, the handler is being added three times. I tried removing the handler before adding it but that has no effect. Any ideas?

I just set the .Tag on the Hyperlink button when I add the event handler and use that as a flag that the handler has been added.

To add to this issue, the problem occurs probably because the LoadingRow event may actually fire several times. The Datagrid will only instantiate the row when it is needed and will recycle it when it goes out of view. Like when you start scrolling the grid.
See the remarks sections for details:
DataGrid.LoadingRow event on msdn

Related

PreviewMouseDown Intercepting SelectedItemChanged Event

I've got a TreeView which acts as the main way of navigating a WPF application.
When the user selects a new item in the TreeView if the page they're leaving has unsaved information we offer the chance to cancel the move to continue working on the current data/save it. This currently happens in the PreviewMouseDown event handler.
It seems however that throwing up a dialog that offers a yes/no/cancel option here prevents the SelectedItemChanged event from ever actually firing, I assume because another mouse click has occured. As a result, if they decline the option to stay on the current page, it's still not changing.
Is there any way to re-fire the event from within PreviewMouseDown so that the SelectedItemChanged event still gets called?
Is there any way to re-fire the event from within PreviewMouseDown so that the SelectedItemChanged event still gets called?
It would be easier to call the event handler manually just as you would call a method. Or better yet, break out the code in the event handler to a standalone method that you call from both the PreviewMouseDown handler and the SelectedItemChanged handler.
The other option would be to change the SelectedItem or IsSelected property so the event fires again.

WPF Telerik gridview click events

I have a telerik gridview that I need to add both a single click and double click event. Basically the user can click a row once for a distinct event and then can also double click for a different event.
Initially I was using the SelectionChanged event to differentiate the two... but now I am having issues with anytime anything changes on the page, this event is fired.
If I implement a single click (MouseDown) event and a MouseDoubleClick event. The single click always overrides the double click and it cannot distinguish between the two - thus never making it to the double click event.
If you're using MVVM, you would probably prefer to attach an ICommand, which will be passed the DataContext of the row that has been clicked on, as a parameter.

Strange issue - mouse click in popup is getting captured by control underneath

I'm displaying a Popup in response to a button click (popup.IsOpen = true;). The popup contains a ComboBox, and when I click an item in the combobox, one of the things the SelectionChanged event does is to hide the popup.
The Popup appears over a DataGrid that I also have on my page, and I'm finding that the mouse-click on the combobox is also being picked up by a MouseUp event that I've got on the DataGrid. Any idea what's going on?
The MouseUp Event has a routing strategy of type Bubbling. Events that use this type of strategy get passed up the chain to parent controls. Since the Popup is a child of the DataGrid, the event will "bubble" up to the DataGrid. If you would rather the event not bubble, you can try using PreviewMouseUp, which has a Tunneling routing strategy, and will "tunnel" down the chain to child controls. Here is a decent overview of Routing Strategies.
I've hit the same issue. Oddly, it doesn't happen when the code is run in the debugger - it only happens in the release version. It really seems to be a bug in WPF. Trying to catch the click and set the event to handled doesn't work.
My workaround is to, when the popup opens, to tell the control underneath to ignore the click.

How to detect a click on the selected row of a RadGridView control

My WPF application uses the Telerik RadGridView control on a few of its screens. I have a requirement that says that whenever the user clicks on a row in the RadGridView, I'm supposed to switch to another screen and display detail information about that row. I hooked up a handler to the SelectionChanged event and this works, except that nothing happens if the user clicks on the selected row a second time. This makes sense, as the selected row isn't being changed.
How can I detect a second click on the same row and have the second screen displayed?
Tony
You could just attach a handler to the MouseUp event on the GridView. Check if there are any selected cells and respond from there. This will fire even if there is already a selection.
The MouseDown event will fire on the mouse click, but before the gridview updates the selction, mouse up should fire when the selection has already been adjusted
You can also attach a handler to each individual cell in code-behind as follows
(this.GridView as RadGridView).AddHandler(
GridViewCell.MouseUpEvent,
new EventHandler<Telerik.Windows.RadRoutedEventArgs>(this.OnMouseUp));
I think you may try to achieve this through the MouseLeftButtonDown event or PreviewMouseLeftButtonDown event.

ContactUp event not fired

In my surface application I have a SurfaceWindow with a SurfaceUserControl on. On the SurfaceUserControl I have a SurfaceButton but the ContactUp (and down) event is not fired. The ContactHoldGesture event is fired though.
Any ideas?
Could you include some code to reproduce? Where are you subscribing to those events?
Most likely what's happening is the contact up and down events are being handled by the button, so they don't fire at the usercontrol level. Try looking at the previewcontactup and previewcontactdown events.
ContactUp and ContactDown are handled by the button itself - that's why the events never get to your code. If you really want to intercept these events, use PreviewContactUp/PreviewContactDown instead. What you probably really need though is to just handle the Click event on the button. Adjust the ClickMode property of the button if you want to change what causes the Click event to be raised.

Resources