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

原文来自icyfox_bupt的博客,转载请注明来自: http://blog.csdn.net/icyfox_bupt/article/details/7560023

想做一个外发光按钮,网上找的所有教程使用的都是 <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文件里没有代码啦,希望能给大家帮助。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值