Andrew Smith

What's in the box - NA for Windows Forms & WPF
BitmapEffects

BitmapEffects should be used sparingly since currently1 they are software rendered but judicious limited usage of them can provide some nice effects for your application. In some cases, their usage is necessary to duplicate a particular look and feel - e.g. using a OuterGlowBitmapEffect to mimic the glow around text in the title area of the ribbon window. However, BitmapEffects are not allowed when running in a limited trust situation - e.g. xbap - so if your template defines a BitmapEffect, that template cannot be used when running in an xbap.

There are several options you could choose. You could create the bitmap effect in code so you can catch any security exceptions that might arise. This option allows you to catch the exception that would be generated when you don't have the security required to create it but it assumes that the developer knows when the bitmap effect will be needed. If you're working with a designer, you'll want to leave it up to them. The look of the element should be kept as separated as possible from the behavior/code behind. Another option is to create two templates and decide in a style trigger which to use depending on whether you're running in an xbap. This too isn't a great option since it means you have to maintain two different templates - more if you have to re-template the element for different themes.

We chose another route - we created the SafeOuterGlowExtension class. This class is a markup extension that can be used to define an OuterGlowBitmapEffect and exposes the same properties available on that class. Since the OuterGlowBitmapEffect is not defined in the xaml, the template can be used even when running in an xbap, in which case the bitmap effect is not created. Currently, this is the only bitmap effect exposed in this manner since it was the only one we needed at the time. If you need to use another bitmap effect, you could follow a similar route for the other bitmap effect classes.

Example usage:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:igWindows="http://infragistics.com/Windows"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <TextBlock Text="This text has a glow"
      BitmapEffect="{igWindows:SafeOuterGlow GlowColor=Yellow}"/>
</Page>

Notes
1. Some of the bitmap effects will be hardware accelerated in a service release due later this year.

MousePanning in WPF

Many applications such as Microsoft Office and web browsers provide the ability to scroll by pressing down the middle mouse button and dragging in the direction that you want to scroll. This feature is often referred to as mouse panning. When you press down the middle mouse button on a scrollable area, an indicator is displayed. This indicator usually has arrows that let you know whether you can scroll vertically and/or horizontally. You can then drag the mouse in a direction to cause the window to scroll.

We had incorporated this functionality into our UIElement framework in Windows Forms but any element that wanted to utilize it had to opt into the feature, override certain members, and process the panning notifications since scrolling functionality is implemented by each control. In WPF, elements that want to allow for scrolling normally do so by using a ScrollViewer. The MousePanningDecorator class takes advantage of this fact to provide mouse panning functionality to any ScrollViewer nested within it. You just need to create an instance of this element within your Window/Page and any ScrollViewer within it will receive mouse panning support.

MousePanningDecorator

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:sys="clr-namespace:System;assembly=mscorlib" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:igWindows="http://infragistics.com/Windows"
>
    <Grid>
        <igWindows:MousePanningDecorator>
            <ScrollViewer HorizontalScrollBarVisibility="Auto">
                <Image Stretch="None" 
                  Source="http://veimages.gsfc.nasa.gov/2433/land_shallow_topo_2048.jpg" />
            </ScrollViewer>
        </igWindows:MousePanningDecorator>
    </Grid>
</Page>

If you want to restyle the indicators, the class exposes several ResourceKey fields that can be used to provide custom ImageSources for the indicators.

Disabled Images in WPF

I think most developers and end users have come to expect that when a menu item or button is disabled that the image and text within that item are displayed as grayed out. This provides a visual indication that the item is not available for use. I can understand why the Image element would not do this by default but I was surprised to find that there wasn't even an option to have it do this for you. If you have an Image within a Button or MenuItem and you disable that element, the Image element within will be disabled but the image it renders will appear no differently than when it was enabled. That is why we created the AutoDisabledImage class. This class derives from Image and provides support for automatically1 rendering an image as disabled when the element is disabled. You use this element in the same way you would an Image element - just set the Source property to the image that you want to display. When the element is disabled, it will handle converting the image to a gray scale version.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:igWindows="http://infragistics.com/Windows"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <StackPanel>
<igWindows:AutoDisabledImage  Source="http://www.infragistics.com/App_Themes/Default/images/logo.gif"
Stretch="None" />
<igWindows:AutoDisabledImage IsEnabled="false" 
Source="http://www.infragistics.com/App_Themes/Default/images/logo.gif"
Stretch="None" />
  </StackPanel>
</Page>

Example using the AutoDisabledImage

Notes
1.  The current implementation only works with a BitmapSource derived ImageSource. If you use a DrawingImage, the Image will continue to appear as it did when it was enabled.