IanG on Tap

Ian Griffiths in Weblog Form (RSS 2.0)

Blog Navigation

April (2018)

(1 item)

August (2014)

(1 item)

July (2014)

(5 items)

April (2014)

(1 item)

March (2014)

(1 item)

January (2014)

(2 items)

November (2013)

(2 items)

July (2013)

(4 items)

April (2013)

(1 item)

February (2013)

(6 items)

September (2011)

(2 items)

November (2010)

(4 items)

September (2010)

(1 item)

August (2010)

(4 items)

July (2010)

(2 items)

September (2009)

(1 item)

June (2009)

(1 item)

April (2009)

(1 item)

November (2008)

(1 item)

October (2008)

(1 item)

September (2008)

(1 item)

July (2008)

(1 item)

June (2008)

(1 item)

May (2008)

(2 items)

April (2008)

(2 items)

March (2008)

(5 items)

January (2008)

(3 items)

December (2007)

(1 item)

November (2007)

(1 item)

October (2007)

(1 item)

September (2007)

(3 items)

August (2007)

(1 item)

July (2007)

(1 item)

June (2007)

(2 items)

May (2007)

(8 items)

April (2007)

(2 items)

March (2007)

(7 items)

February (2007)

(2 items)

January (2007)

(2 items)

November (2006)

(1 item)

October (2006)

(2 items)

September (2006)

(1 item)

June (2006)

(2 items)

May (2006)

(4 items)

April (2006)

(1 item)

March (2006)

(5 items)

January (2006)

(1 item)

December (2005)

(3 items)

November (2005)

(2 items)

October (2005)

(2 items)

September (2005)

(8 items)

August (2005)

(7 items)

June (2005)

(3 items)

May (2005)

(7 items)

April (2005)

(6 items)

March (2005)

(1 item)

February (2005)

(2 items)

January (2005)

(5 items)

December (2004)

(5 items)

November (2004)

(7 items)

October (2004)

(3 items)

September (2004)

(7 items)

August (2004)

(16 items)

July (2004)

(10 items)

June (2004)

(27 items)

May (2004)

(15 items)

April (2004)

(15 items)

March (2004)

(13 items)

February (2004)

(16 items)

January (2004)

(15 items)

Blog Home

RSS 2.0

Writing

Programming C# 5.0

Programming WPF

Other Sites

Interact Software

WPF VisualBrush Magnifier Updated

Wednesday 28 March, 2007, 02:16 AM

A couple of years ago, I showed an example where I used a VisualBrush to add a magnifier to a WPF application. The example used to be built around Beta 1 of WPF. I finally got around to updating the sample so that it runs with the final release of WPF.

Mostly it was a case of updating the XML namespaces, and expanding out the linear gradient brushes. (You used to be able to specify a gradient brush inline in a XAML attribute, whereas you now have to expand the thing out in full.) But I was able to simplify a couple of things too.

The old example used a bit of a hack to make mouse clicks and mouse-over behaviour work correctly. The magnifying glass graphic had a tiny hole in it just under where the mouse pointer was. WPF now offers a much better solution: the IsHitTestVisible property. You can set this to false on any element, making it effectively invisible to the mouse, allowing whatever’s underneath to handle mouse input as though the element were not there.

Also, previously I had to write some code to hook up the state of the check box with the visibility of the magnifier rather than using data binding. Now, WPF offers the BooleanVisibilityConverter class, which makes it really easy to use data binding to connect the check box’s Boolean IsChecked property with the enumeration-typed Visibility property. (Converters are not a new technique. I could have written an equivalent converter before, but it seemed less effort just to write the event handling code. Now the converter is built in, it makes binding these properties a breeze.)

Also, the bug I mentioned that caused the brush to be cropped appears to have been a bug in the preview of WPF that was available two years ago. Unsurprisingly, this has been fixed now that WPF has shipped.

[Update 28th March 2007: If you just want to play with the example, rather than downloading the code, here's an XBAP version.]

Copyright © 2002-2024, Interact Software Ltd. Content by Ian Griffiths. Please direct all Web site inquiries to webmaster@interact-sw.co.uk