2017-05-25 28 views
0

我想要動畫DropShadowEffect我已經應用到一個網格和一個BlurEffect,我已經應用到另一個網格。Animatint Blur效果在一個樣式工程,但動畫DropShadowEffect導致錯誤?

模糊動畫似乎工作正常,這是代碼。

<Style x:Key="BluredGridStyle" TargetType="{x:Type Grid}"> 
      <Style.Triggers> 
       <Trigger Property="extentions:GridExtention.IsBlured" Value="True"> 
        <Trigger.EnterActions> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation Storyboard.TargetProperty="(Effect).Radius" From="0" To="10" Duration="0:0:0.2"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </Trigger.EnterActions> 
        <Trigger.ExitActions> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation Storyboard.TargetProperty="(Effect).Radius" From="10" To="0" Duration="0:0:0.2"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </Trigger.ExitActions> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 

<Grid Background="{DynamicResource BrHostBackground}"> 
    <Grid extentions:GridExtention.IsBlured="{Binding BackgroundIsBlured}" Style="{StaticResource BluredGridStyle}"> 
     <Grid.Effect> 
      <BlurEffect x:Name="BlurEffect" Radius="0"/> 
     </Grid.Effect> 
    </Grid> 
</Grid> 

但是,當我嘗試使用陰影我會得到錯誤。這是我的初始代碼。

 <Style x:Key="DropShaodowGridStyle" TargetType="{x:Type Grid}"> 
      <Style.Triggers> 
       <Trigger Property="Visibility" Value="Visible"> 
        <Trigger.EnterActions> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation Storyboard.TargetProperty="(Effect).BlurRadius" From="0" To="80" Duration="0:0:0.2"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </Trigger.EnterActions> 
        <Trigger.ExitActions> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation Storyboard.TargetProperty="(Effect).BlurRadius" From="80" To="0" Duration="0:0:0.2"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </Trigger.ExitActions> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 

    <Grid Visibility="{Binding HardwareLoadingVisibility}"> 
     <Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center" Background="White" Width="550" Height="250" Style="{DynamicResource DropShaodowGridStyle}"> 
      <Grid.Effect> 
       <DropShadowEffect ShadowDepth="0" Opacity="0.8"/>      
      </Grid.Effect>    
     </Grid> 
    </Grid> 

這會產生以下錯誤

InvalidOperationException: Cannot resolve all property references in the property path '(Effect).BlurRadius'. Verify that applicable objects support the properties.

如果我的屬性更改爲(Effect).Radius我得到同樣的錯誤。

我也試圖改變其產生這個錯誤

InvalidOperationException: 'Effect' property does not point to a DependencyObject in path '(0).(1)'.

回答

0

看起來像我找到了答案的財產,以(UIElement.Effect).(DropShadowEffect.BlurRadius)

我不得不爲樣式中的屬性分配一個默認值。

<Style x:Key="DropShaodowBorderStyle" TargetType="{x:Type Border}"> 
      <Setter Property="Effect"> 
       <Setter.Value> 
        <DropShadowEffect ShadowDepth="0" BlurRadius="0"></DropShadowEffect> 
       </Setter.Value> 
      </Setter> 
      <Style.Triggers> 
       <Trigger Property="Visibility" Value="Visible"> 
        <Trigger.EnterActions> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation Storyboard.TargetProperty="(UIElement.Effect).BlurRadius" From="0" To="80" Duration="0:0:2"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </Trigger.EnterActions> 
        <Trigger.ExitActions> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation Storyboard.TargetProperty="(UIElement.Effect).BlurRadius" From="80" To="0" Duration="0:0:2"/> 
          </Storyboard> 
         </BeginStoryboard> 
        </Trigger.ExitActions> 
       </Trigger> 
      </Style.Triggers> 
     </Style>