WPF实现图片倒影

时间:2021-07-10 21:54:50

比较简单,主要用到ScaleTransfrom类和VisualBrush类

 <Window x:Class="实现图片倒影的方式.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="">
<Grid HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions> <Image Grid.Row="" Name="image" Source="C:\Users\天天开心\Pictures\58c3cbef76094b3605d27002a5cc7cd98c109d0f.jpg" Margin=""></Image>
<Rectangle Grid.Row="" Margin="">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=image}">
<VisualBrush.RelativeTransform>
<ScaleTransform ScaleY="-1" CenterY=".5"></ScaleTransform>
</VisualBrush.RelativeTransform>
</VisualBrush>
</Rectangle.Fill> <Rectangle.OpacityMask>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Black" Offset=""></GradientStop>
<GradientStop Color="Transparent" Offset=".6"></GradientStop>
</LinearGradientBrush>
</Rectangle.OpacityMask> </Rectangle> </Grid>
</Window>

测试效果:

WPF实现图片倒影