您的位置:首页 > 职场人生

【.Net码农】WPF .NET 4.0下实现外发光效果

2015-05-11 10:21 501 查看
原文来自icyfox_bupt的博客,转载请注明来自:/article/1897201.html想做一个外发光按钮,网上找的所有教程使用的都是<Button.BitmapEffect>这个标签
但是我把代码复制以后发现不可以使用,经过查找资料,发现这个标签在.NET 3.5的时候已经过时了,但是写上以后并不会报错,怪不得我使用.NET 4.0的时候没有任何反应。
那在.NET 3.5以上要做外发光应该怎么做呢? 经过查找外国网站,笔者发现了一个办法,与大家分享。.NET 4.0中只能用EFFECT标签来使用。将其中的
DropShadowEffect
ShadowDepth
改为0即可


示例:
XAML代码:
<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="350" Width="525">
<Grid Background="Black" Height="325" Width="503">
<Button Content="这是不发光的" Margin="152,59,268,219">
</Button>
<Button Content="这是发光的"  Margin="152,123,268,156">
<Button.Effect>
<DropShadowEffect ShadowDepth="0"
Color="White"
Opacity="1"
BlurRadius="20"/>
</Button.Effect>
</Button>
</Grid>
</Window>
<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="350" Width="525">
<Grid Background="Black" Height="325" Width="503">
<Button Content="这是不发光的" Margin="152,59,268,219">
</Button>
<Button Content="这是发光的"  Margin="152,123,268,156">
<Button.Effect>
<DropShadowEffect ShadowDepth="0"
Color="White"
Opacity="1"
BlurRadius="20"/>
</Button.Effect>
</Button>
</Grid>
</Window>
.cs文件里没有代码啦,希望能给大家帮助。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: