Export (0) Print
Expand All

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 sealed class BlurEffect : Effect
<BlurEffect .../>

The BlurEffect type exposes the following members.

  NameDescription
Public methodBlurEffectInitializes a new instance of the BlurEffect class.
Top

  NameDescription
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.
Top

  NameDescription
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.)
Top

  NameDescription
Public fieldStatic memberRadiusPropertyIdentifies the Radius dependency property.
Top

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


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


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">
    <StackPanel.Resources>
        <Style x:Name="buttonStyle" TargetType="Button" >
            <Style.Setters>
                <Setter Property = "Effect" >
                    <Setter.Value>
                        <BlurEffect Radius="10" />
                    </Setter.Value>
                </Setter>
            </Style.Setters>
        </Style>
    </StackPanel.Resources>
    <Button Width="200" Height="30" Style="{StaticResource buttonStyle}" 
            Margin="20" Content="Blurning down the House!" />
</StackPanel>


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

Run this sample


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



// Toggle Blur effect.
private void OnClickBlurButton(object sender, RoutedEventArgs args)
{
    // Toggle effect
    if (((Button)sender).Effect != null)
    {
        ((Button)sender).Effect = null;
    }
    else
    {
        // Get a reference to the Button.
        Button myButton = (Button)sender;

        // Initialize a new BlurEffect that will be applied
        // to the Button.
        BlurEffect myBlurEffect = 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;
    }
}


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


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



private void StartAnimation(object sender, RoutedEventArgs args)
{
    myStoryboard.Begin();
}


Silverlight

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

ADD
Show:
© 2014 Microsoft