Skip to content →

Tag: c#

Unhandling previously handled events in Silverlight

What?

You may well find yourself wanting to attach to an event which has already been handled inside a control with no way to override and prevent the event from being handled. As seen in my prior post to this, you can make use of the AddHandler method. I am going to use the Backspace key down in a TextBox as an example, the event is only raised and not handled when the TextBox is empty. (This can be seen in the sample application in the output coming from the behavior)

Leave a Comment

Detect whether the mouse is down in Silverlight

After recently searching for a way to do this and finding nothing I thought I would share a solution. It involves using the ever useful AddHandler method on the UIElement you wish to detect the mouse down on and simply setting a flag. Job done.

It is worth noting that popups and child windows may appear on top of the UIElement which the handler is attached to.

2 Comments

Using Silverlight and JavaScript to prevent leaving a webpage

Recently I have been thinking about applications with data input and the problems of being in a browser. One of the perils of being in a browser is that a user may have some unsaved data input tasks. The data can be easily lost by accidently navigating to a different webpage, closing the browser or closing the tab.

Preventing this is relatively easy making use of Silverlight and JavaScript communication in conjunction with the window.onbeforeunload function. See below for example and code snippets. 😀

2 Comments