WPF窗口阴影效果 [英] WPF window shadow effect

查看:659
本文介绍了WPF窗口阴影效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WPF技术的新手。我在WPF中有以下窗口声明:

I am new to WPF technology. I have the following window declaration in WPF:

<Window x:Class="CustomWindows.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="480" Width="640" ScrollViewer.VerticalScrollBarVisibility="Disabled" WindowStyle="None" AllowsTransparency="True">
    <Window.Effect>
        <DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" ShadowDepth="2"/>
    </Window.Effect>
    <Grid>

    </Grid>
</Window>

但是当我运行它时,没有出现阴影。我该怎么办,或者误解在哪里?

But when I run it, the shadow does not appear. What can I do, or where is the misstake?

推荐答案

DropShadowEffect 不能应用于 Window 。相反,如果要覆盖默认的窗口外观,则必须将效果应用于窗口中包含的其他元素:

DropShadowEffect cannot be applied to a Window. Instead, if you want to override the default window appearance, you have to apply the effect to some other element contained in the window:

<Window x:Class="WpfApplication2.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" WindowStyle="None" AllowsTransparency="True" Background="Transparent">
    <Grid Margin="20" Background="Red">
        <Grid.Effect>
            <DropShadowEffect BlurRadius="15" Direction="-90" RenderingBias="Quality" ShadowDepth="2"/>
        </Grid.Effect>
        ...

    </Grid>
</Window>

这篇关于WPF窗口阴影效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆