How to capture a mouse click on an Item in a ListBox in WPF?

I believe that your MouseLeftButtonDown handler is not called because the ListBox uses this event internally to fire its SelectionChanged event (with the thought being that in the vast majority of cases, SelectionChanged is all you need). That said, you have a couple of options. First, you could subscribe to the PreviewLeftButtonDown event instead. Most …

Read more

Weak event handler model for use with lambdas

‘The’ answer (Read more below if you want to see how I got to this solution) Usage, given a control with a vanilla MouseDown event, and a specific EventHandler<ValueEventArgs> ValueEvent event: // for ‘vanilla’ events SetAnyHandler<Subscriber, MouseEventHandler, MouseEventArgs>( h => (o,e) => h(o,e), //don’t ask me, but it works*. h => control.MouseDown += h, h …

Read more

Removing event handlers

It is the same. The second is merely syntactic sugar for the first, and equality comparison is overloaded appropriately for delegate types: Two delegates of the same type with the same targets, methods, and invocation lists are considered equal. Source: MSDN, Delegate.Equality Operator

Subscribe to INotifyPropertyChanged for nested (child) objects

since I wasn’t able to find a ready-to-use solution, I’ve done a custom implementation based on Pieters (and Marks) suggestions (thanks!). Using the classes, you will be notified about any change in a deep object tree, this works for any INotifyPropertyChanged implementing Types and INotifyCollectionChanged* implementing collections (Obviously, I’m using the ObservableCollection for that). I …

Read more

socket.io: disconnect event isn’t fired

Put your on disconnect code inside your on connect block and edit it a bit like so: io.sockets.on(‘connection’, function (socket) { count++; io.sockets.emit(‘count’, { number: count }); socket.on(‘disconnect’, function () { console.log(‘DISCONNESSO!!! ‘); count–; io.sockets.emit(‘count’, { number: count }); }); }); This way you’re detecting when a specific socket (specifically the socket you pass to …

Read more

Unloading/Removing content from an iFrame

The other solutions use innerHTML, which won’t always work in XHTML. They also only clear document.body (anything in the <head> is still present). Here is a solution that uses the DOM: var frame = document.getElementById(“myFrame”), frameDoc = frame.contentDocument || frame.contentWindow.document; frameDoc.removeChild(frameDoc.documentElement); This solution uses innerHTML: var frame = document.getElementById(“myFrame”), frameDoc = frame.contentDocument || frame.contentWindow.document; frameDoc.documentElement.innerHTML …

Read more

Event to detect System wake up from sleep in C#

SystemEvents.PowerModeChanged += OnPowerChange; private void OnPowerChange(object s, PowerModeChangedEventArgs e) { switch ( e.Mode ) { case PowerModes.Resume: break; case PowerModes.Suspend: break; } } You should probably read this: http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.powermodechanged.aspx