BlurEffect Class

Represents an effect that you can apply to an object that simulates looking at the object through an out-of-focus lens.

Namespace:  System.Windows.Media.Effects
Assembly:  System.Windows (in System.Windows.dll)

Public NotInheritable Class BlurEffect _
	Inherits Effect
<BlurEffect .../>

The BlurEffect type exposes the following members.

Public methodBlurEffectInitializes a new instance of the BlurEffect class.

Public propertyDispatcherGets the Dispatcher this object is associated with. (Inherited from DependencyObject.)
Protected propertyEffectMappingWhen overridden in a derived class, transforms mouse input and coordinate systems through the effect. (Inherited from Effect.)
Public propertyRadiusGets or sets the amount of blurring applied by the BlurEffect.

Public methodCheckAccessDetermines whether the calling thread has access to this object. (Inherited from DependencyObject.)
Public methodClearValueClears the local value of a dependency property. (Inherited from DependencyObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetAnimationBaseValueReturns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueReturns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodReadLocalValueReturns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.)
Public methodSetValueSets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Public fieldStatic memberRadiusPropertyIdentifies the Radius dependency property.

The following illustration shows a BlurEffect applied to a visual object (in this case, applied to a Button).

A blurry button versus not blurry

In addition to creating blur effects by using BlurEffect, you can create a drop shadow by using DropShadowEffect.

You can apply only one effect directly to an element at a time. For example, you cannot apply a BlurEffect and a DropShadowEffect to the same element directly. However, you can apply an effect to the container of an element and therefore apply the effect to the nested child. For instance, you could apply a DropShadowEffect to a Button and then apply a BlurEffect to a Grid that contains the Button. This would create a blurry button with a drop shadow. However, stacking effects on one another in this way may have adverse effects on the performance of your application.

Note   Silverlight shader effects are rendered in software mode. Any object that applies an effect will also be rendered in software. Performance is degraded the most when using effects on large visuals or animating properties of an effect. This is not to say that you should not use shader effects in this way at all, but you should use caution and test thoroughly to ensure that your users are getting the experience you expect.

The following examples show the following:

  • How to use simple markup to blur an object by using XAML.

  • How to use a Style to apply the effect to one or more objects.

  • How to use code to apply the effect to an object.

  • How to use an animation to animate the properties of an effect applied to an object.

The following example shows how to use a BlurEffect to create a blurry Button.

Run this sample

    <Button Content="You Can't Read This!"  Width="200">
            <BlurEffect Radius="10" />

The following example shows how to use a Style to apply a BlurEffect to a Button.

Run this sample

<StackPanel x:Name="LayoutRoot" Background="White">
        <Style x:Name="buttonStyle" TargetType="Button" >
                <Setter Property = "Effect" >
                        <BlurEffect Radius="10" />
    <Button Width="200" Height="30" Style="{StaticResource buttonStyle}" 
            Margin="20" Content="Blurning down the House!" />

The following example shows how to use code to apply a BlurEffect to a Button when it is clicked.

Run this sample

    <Button Click="OnClickBlurButton" Width="200" Margin="10" 
            Content="Click to Blur!" />

' Toggle Blur effect.
Private Sub OnClickBlurButton(ByVal sender As Object, ByVal args As RoutedEventArgs)

    ' Toggle effect
    If (Not (CType(sender, Button).Effect) Is Nothing) Then
        CType(sender, Button).Effect = Nothing

        ' Get a reference to the Button.
        Dim myButton As Button = CType(sender, Button)

        ' Initialize a new BlurEffect that will be applied
        ' to the Button.
        Dim myBlurEffect As BlurEffect = New BlurEffect

        ' Set the Radius property of the blur. This determines how 
        ' blurry the effect will be. The larger the radius, the more
        ' blurring. 
        myBlurEffect.Radius = 10

        ' Apply the effect to the Button.
        myButton.Effect = myBlurEffect
    End If
End Sub

The following example shows how to animate the Radius property of the BlurEffect to make the Button become blurry and return to normal after it is clicked.

Run this sample

        <Storyboard x:Name="myStoryboard">
            <!-- Blur the Button and then animate back to normal. -->
             From="0" To="40" Duration="0:0:0.3"
             AutoReverse="True" />
    <Button Content="Click to Blur ME!" Click="StartAnimation" Width="200"
            <BlurEffect x:Name="myBlurBitmapEffect" Radius="0" />

Private Sub StartAnimation(ByVal sender As Object, ByVal args As RoutedEventArgs)
End Sub


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions