How to: Use a Custom Visual Effect

This example shows how to use a custom effect in Extensible Application Markup Language (XAML).

Custom effects are created with unmanaged API and create a Component Object Model (COM) dynamic-link library (DLL). To use custom effect in managed code, a managed assembly is used to define the BitmapEffect and to interact with the Component Object Model (COM) library. To use this custom effect in an application, the assembly must be referenced and the effect must use the namespace referenced by the assembly. For the complete sample, see Custom BitmapEffect Sample - RGBFilter.

Example

The following example shows how to define a namespace and reference the assembly that implements the custom effect.

<Window x:Class="RGBFilterEffectTest.Window1"
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
    Title="RGBFilterEffectTest" Height="400" Width="300"
    xmlns:RGBFilter="clr-namespace:RGBFilter;assembly=ManagedRGBFilterBitmapEffect"
    xmlns:MappingPIGen1="clr-namespace:RGBFilter;assembly=ManagedRGBFilterBitmapEffect">

The following example uses the custom effect by referencing the namespace provided in the above example.

<Image Name="RTB" Source="images/kittens.jpg">
  <Image.BitmapEffect>
    <RGBFilter:RGBFilterBitmapEffect >
      <RGBFilter:RGBFilterBitmapEffect.Red>
        <Binding ElementName="redSlider" Path="Value"/>
      </RGBFilter:RGBFilterBitmapEffect.Red>
      <RGBFilter:RGBFilterBitmapEffect.Green>
        <Binding ElementName="greenSlider" Path="Value"/>
      </RGBFilter:RGBFilterBitmapEffect.Green>
      <RGBFilter:RGBFilterBitmapEffect.Blue>
        <Binding ElementName="blueSlider" Path="Value"/>
      </RGBFilter:RGBFilterBitmapEffect.Blue>
    </RGBFilter:RGBFilterBitmapEffect >
  </Image.BitmapEffect>
</Image>

See Also

Tasks

Custom BitmapEffect Sample - RGBFilter

Concepts

Bitmap Effects Overview

Reference

Unmanaged BitmapEffect API