I need to fit the VisualBrush used into the button to the entire window. The VisualBrush is linked to an Image that is stretched to the entire visualization, but in the visual that image starts to appear in the corner of the button.
<Button x:Name="button" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Acquista ora- $23.99" FontSize="48" BorderBrush="{x:Null}">
<Button.Background>
<VisualBrush Visual="{Binding ElementName=img}" Stretch="None" AlignmentX="Center" AlignmentY="Center" ViewboxUnits="RelativeToBoundingBox" ViewportUnits="RelativeToBoundingBox" />
</Button.Background>
</Button>
How can I do? Thanks in advance.
If want to blur the image behind the
Button(or a transparent control in general) you have to follow a different approach.You need the exact tile of the image in order to blur it using the
BlurEffect.In order to not blur the
Buttonitself, you must add alayer beneath the button that has theBlurEffectapplied.The following example extends a
ContentControlnamedBlurHostthat renders theContente.g., theButton, on top of aBorderelement that will actualy blur the background using aVisualBrush.The brush itself has a tile defined that is located at the position of the
BlurHostwhich hosts theButton(or any other transparent control).The basic steps to implement a blurred background:
Usage example
MainWindow.xaml
Implementation example
The implementation is simple. You have to add property changed handlers in order to make the control dynamic.
BlurHost.cs
The
ContentControlserves as a container. The blurred background is visible at the transparent areas of the content.Generic.xaml
The default
Stylefor theBlurHost. The Generic.xaml file is located in the Themes folder of the application (project).