adamnathan.netSubscribe to this blogMetro Web BrowserTODO ListAlarm ClockTip CalculatorSound RecorderGroceriesPick a CardNotepadStopwatchMetronomePinned SearchesFake CallMood RingCocktailsTODO ListAlarm ClockTip CalculatorSound RecorderGroceriesPick a CardNotepadStopwatchMetronomePinned SearchesFake CallMood RingCocktails
 Tuesday, November 02, 2010

The application bar automatically makes your white-on-transparent images white under the dark theme and black under the light theme. You can accomplish this same effect with your own custom images, without relying on custom code to swap images based on the theme (although that works, too).

The trick is to use the image as an opacity mask for a theme-colored element, such as a rectangle. For example:

<Rectangle Width="48" Height="48" Fill="{StaticResource PhoneForegroundBrush}">
  <Rectangle.OpacityMask>
    <ImageBrush ImageSource="/Images/icon.png"/>
  </Rectangle.OpacityMask>
</Rectangle>

The Groceries app uses this technique to make all of its non-application-bar images show up nicely for both themes, for example:

blog1  blog2

Be aware that opacity masks are expensive performance-wise, but for small, static content I think you'll be just fine.

Tuesday, November 02, 2010 6:25:42 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0] - Trackback    
Comments are closed.
<November 2010>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
Adam's Books
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© 2012 Adam Nathan