Search code examples
c#xamluwpuwp-xamlwindows-composition-api

Class not finding when using XamlCompositionBrushBase


So I tried to use BackdropBrush with XamlCompositionBrushBase creating a class called BackdropBlurBrush, but when I call it from XAML It doesn’t find the class. I created the class on the main project. See the error here.

Sample on GitHub: https://github.com/vitorgrs/HostBackdrop/


Solution

  • Your custom composition brush is not a UIElement and that's why it cannot be placed onto the XAML visual tree directly.

    Try adding it as a brush for an element -

    <Grid>
        <Grid.Background>
            <local:BackdropBlurBrush BlurAmount="5" />
        </Grid.Background>
    </Grid>
    

    You normally want to place your blur brush on top of your background image like this -

    <Grid x:Name="Root">
        <Grid.Background>
            <ImageBrush Stretch="UniformToFill" ImageSource="background.jpg"/>
        </Grid.Background>
    
        <Rectangle>
            <Rectangle.Fill>
                <local:BackdropBlurBrush BlurAmount="5" />
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
    

    enter image description here