3

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/

Justin XL
  • 38,763
  • 7
  • 88
  • 133

1 Answers1

3

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

Justin XL
  • 38,763
  • 7
  • 88
  • 133
  • 1
    Now it makes sense. :) When I saw the error, I just thought it was not finding the class itself, and not that it wasn't supposed to work there. I forgot that, well, it's a brush. Thanks. :) – Vitor Mikaelson Jul 16 '17 at 04:25