Different behaviour Key F5

Topics: Prism v4 - Silverlight 4
Nov 24, 2010 at 11:04 AM
Edited Nov 24, 2010 at 12:43 PM

After updatig from Prism 2.2 to Prism 4 i experienced some different behaviour for Key F5.


I've a key handler/EventAggregator in my shell to refresh all my views:

public Shell()
   // Hinzufuegen eines Handlers fuer das KeyDown Event (F5=Refresh)
   // Alle Events der in der Dokumentenhierarchie untergeordneten Elemente werden nach oben geroutet (Bubbling)   
// Hier wird das Event gefangen und das Refresh-Event wird veroeffentlicht. // Alle, die dieses Event abonniert haben, koennen dann darauf reagieren und den Refresh der Views ausfuehren AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(UserControl_KeyDown), true); } public Shell(IEventAggregator eventAggregator) { InitializeComponent(); AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(UserControl_KeyDown), true); this.eventAggegator = eventAggregator; } // // Wurde F5 gedrueckt, wird das Refresh Event veroeffentlicht! // Jedes Event muss ein Payload haben. Daher ist einfach der Typ string angegeben, auch wenn das Event ohne diesen Parameter // ausgefuehrt werden koennte! private void UserControl_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.F5) { CaptureControl.Infrastructure.RefreshEvent refreshEvent = this.eventAggegator.GetEvent<CaptureControl.Infrastructure.RefreshEvent>(); refreshEvent.Publish("Refresh"); } }



This does not work anymore, because F5 now reloads the browser tab. Is this a known behaviour with Prism 4 and what can be done to make use of F5?


kind regards



Nov 24, 2010 at 3:27 PM
Edited Nov 24, 2010 at 3:29 PM

Hi Joachim,

There are no known changes in Prism that alter the way key events are handled.

Your issue doesn't seem to be related to Prism. It's probably related to the browser, as there are differences in the way the browsers handle keyDown events. If you don't want the browser to reload the tab on F5, you need to intercept the event using JavaScript.

You might find the following threads from the Silverlight forum useful to your scenario:

How to handle browser F5 key - do not try to refresh silverlight page

Capturing Function Keys (F5, F3, F1)

I hope you find this helpful.

Guido Leandro Maliandi