代码改变世界

WPF Behaviors之玻璃效果及其扩展

2011-06-23 12:15  硕硕  阅读(2168)  评论(4编辑  收藏  举报

废话不多说,直接上代码上图

相关控件下载

XAML

<Window x:Class="GlassTest.Window2"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i
="http://schemas.microsoft.com/expression/2009/interactivity"
xmlns:local
="clr-namespace:GlassTest"
xmlns:ShaderEffectLibrary
="clr-namespace:ShaderEffectLibrary;assembly=ShaderEffectLibrary"
Title
="Window2" Height="300" Width="300">
<Grid>
<Grid x:Name="grid2">
<Grid x:Name="grid1">
<Grid x:Name="grid" HorizontalAlignment="Stretch" 
          VerticalAlignment="Stretch" Width="Auto" Height="Auto">
<Image x:Name="image" Margin="0,0,0,0" 
             Source="ws_Vista_Background_1600x1200.jpg" Stretch="Fill"/>
</Grid>
</Grid>
<Border Margin="133.667,35.333,28,51.334" Background="#FF545454" 
        BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="8,8,8,8">
<i:Interaction.Behaviors>
<local:GlassBehavior Visual="{Binding ElementName=grid1, Mode=OneWay}">
<local:GlassBehavior.Effect>
<BlurEffect/>
</local:GlassBehavior.Effect>
</local:GlassBehavior>
</i:Interaction.Behaviors>
<Border.Effect>
<DropShadowEffect BlurRadius="20" ShadowDepth="1"/>
</Border.Effect>
<StackPanel>
</StackPanel>
</Border>
</Grid>
<Border Margin="32.001,8,129.666,112" Background="#FF545454" 
      BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="8,8,8,8">
<i:Interaction.Behaviors>
<local:GlassBehavior Visual="{Binding ElementName=grid2, Mode=OneWay}">
<local:GlassBehavior.Effect>
<ShaderEffectLibrary:LightStreakEffect />
</local:GlassBehavior.Effect>
</local:GlassBehavior>
</i:Interaction.Behaviors>
<Border.Effect>
<DropShadowEffect BlurRadius="25" ShadowDepth="1"/>
</Border.Effect>
<StackPanel>
</StackPanel>
</Border>
</Grid>
</Window>

是不是很简单呢,ShaderEffectLibrary这个里面包含了很多效果哦