Drop Shadow effect in Universal Windows Applicatio

2019-01-15 19:35发布

问题:

I'm looking for an easy way to add a Drop Shadow effect like in WPF, using XAML only. I would like to apply it for the elements in a ListView.

I haven't found anything more than experiments like this: https://blogs.windows.com/buildingapps/2016/09/12/creating-beautiful-effects-for-uwp/#BIRDSebvmJwAFY5Y.97

It seems that it would requiere a lot of code-behind. I would like to avoid it. 

回答1:

If you want to do it yourself with the Composition API, it's quite some work indeed. Luckily we got a great community, and one of those open source projects is the UWP Community Toolkit. This toolkit contains a DropShadowPanel control that does the hard work for you.

<controls:DropShadowPanel BlurRadius="4.0"
                          ShadowOpacity="0.70"
                          OffsetX="5.0"
                          OffsetY="5.0"
                          Color="Black">
    <Image Width="200" Source="Unicorn.png" Stretch="Uniform"/>
</controls:DropShadowPanel>    

Note that you'll have to set the app version to 10.0.14393.0 (Anniversary Update) for this effect.



标签: c# .net xaml uwp