2010-08-21 72 views
2

我正在使用自定義窗口(allowtransparency = true,resize = none,窗口樣式=無)的c#wpf應用程序。wpf:自定義窗口投影

現在我想添加類似於zune pc軟件的投影。我對此進行了閱讀,其中包含的陰影效果並未覆蓋我窗口的所有角度,據說它會導致性能下降。

我想要這樣實現它:我添加一個邊距到我的佈局網格,當我最大化應用程序時,我編程刪除。

添加可應用於網格的陰影的最佳方式是什麼,它不會導致性能下降並在各個方向上投影?

回答

4

-75的方向,ShadowDepth爲2,BlurRadius爲27幫助我。

最好的方法是使用混合來做到這些。

HTH

+2

只是想指出 - 即使有這麼大的模糊,2的ShadowDepth在這裏出現了驚人的巨大差異。通過將ShadowDepth設置爲0,你可以得到一個完全居中的「陰影」(更多的是外部光),但是絕對沒有彈出來,即使在一個大物體上,2的ShadowDepth將它牢固地建立爲陰影而不是輪廓。 – Ben 2012-02-14 15:38:38

4

DropShadowEffect不會「殺死性能」......它使用硬件加速來呈現,並且在窗口上渲染陰影對於當前的GPU來說不是什麼大問題。你可能會用DropShadowBitmapEffect,這是軟件渲染混淆。無論如何,所有BitmapEffects在3.5 SP1中已經過時,並且在4.0中完全不工作,現在只能使用Effects

+0

所以我用dropshadoweffect我的網呢?我怎樣才能讓它在所有方向上投下陰影,還是我必須應用多種效果..? – internetmw 2010-08-22 01:00:25

2

建立了王子代碼,我想粘貼最終產品。

<Window x:Class="RDNScoreboard.Views.InitialWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="InitialWindow" Height="300" Width="300" 
    WindowStyle="None" 
AllowsTransparency="True" Background="Transparent" 
    BorderThickness="3" > 
<Border> 
    <Border.Effect> 
     <DropShadowEffect BlurRadius="27" Color="Black" Opacity="0.8" ShadowDepth="2" Direction="-75" /> 
    </Border.Effect> 
    <Grid Background="White" > 
    </Grid> 
</Border> 

+0

謝謝,這種方式效果很好。 – Kross 2016-07-21 11:04:20

+0

這不考慮窗口鉻,這在實踐中是可怕的。 – 2016-11-19 13:41:17

7

我想在此發佈的解決方案,但他們無一讓我接近我想要的(參見下圖)的最終結果。所以我嘗試了幾個不同的東西,並在這裏發佈我的解決方案,以防萬一有人對實現類似的東西感興趣。順便說一句:如果你可以改進我的解決方案,請讓我知道,因爲我覺得目前有點多餘。

Window with blue drop shadow effect

現在好了驅動這種效果的代碼:

<Window ... 
    WindowStyle="None" AllowsTransparency="True" Background="Transparent" 
    ...> 

    <Border> 
     <Border.Effect> 
      // opacity does not need to be specified but it looks cooler when you do 
      <DropShadowEffect BlurRadius="20" ShadowDepth="0" Opacity="0.8" 
       Color="Blue" /> 
     </Border.Effect> 

     // make sure the value for Grid Margin is the same as DropShadowEffect 
     // BlurRadius 
     <Grid Background="White" Margin="20"> 

      // I tried setting borderthickness and borderbrush to the previous 
      // <Border> element but instead of the border being shown right after 
      // the grid and before the drop shadow, it would show after the drop 
      // shadow making the overall effect very ugly 
      <Border BorderThickness="1" BorderBrush="Black"> 
       // now you can specify whatever you want to display in the window 
       <Grid> 
        .... 
       </Grid> 
      </Border> 
     </Grid> 
</Window> 
+0

感謝您的幫助! – mbdavis 2013-11-20 15:50:24