2010-07-23 39 views
0

Opacity属性我有一个ListViewItem的控制样式:错误,同时增加使用DoubleAnimation是

<EventTrigger RoutedEvent="ListViewItem.MouseEnter"> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.Opacity"        
           From="0.0" To="1.0" Duration="0:0:0.5" AutoReverse="False" SpeedRatio="2" /> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger> 

       <EventTrigger RoutedEvent="ListViewItem.MouseLeave"> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.Opacity"        
           From="1.0" To="0.0" Duration="0:0:0.5" AutoReverse="False" SpeedRatio="2" /> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger> 

我想,当鼠标在ListViewItem的,项目的边界慢慢出现,当鼠标离开它,边界效应消失, 但我得到这个错误,当鼠标都要离开项目:

Cannot resolve all property references in the property path 'BitmapEffect.Opacity'. Verify 
that applicable objects support the properties. 

注意的是,当我只用第一EventTrigger其路由到ListViewItem.MouseEnter,程序工作正确的!但它并不好看!

我在使用OuterGlowBitmapEffect!

   <Trigger Property="IsMouseOver" Value="true"> 
        <Setter Property="BitmapEffect"> 
         <Setter.Value> 
          <OuterGlowBitmapEffect GlowColor="SkyBlue" GlowSize="20" /> 
         </Setter.Value> 
        </Setter> 
        <Setter Property="Foreground" Value="Black" /> 
       </Trigger> 

回答

3

我正在尝试使用BitmapEffect,它与上面的代码一样工作正常。

<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}"> 
     <Setter Property="BitmapEffect"> 
      <Setter.Value> 
       <OuterGlowBitmapEffect GlowColor="Blue" GlowSize="5" /> 
      </Setter.Value> 
     </Setter> 
     <Style.Triggers> 
      <EventTrigger RoutedEvent="ListViewItem.MouseEnter"> 
       <EventTrigger.Actions> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.Opacity"        
          From="0.0" To="1.0" Duration="0:0:0.5" AutoReverse="False" SpeedRatio="2" /> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger.Actions> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="ListViewItem.MouseLeave"> 
       <EventTrigger.Actions> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.Opacity"        
          From="1.0" To="0.0" Duration="0:0:0.5" AutoReverse="False" SpeedRatio="2" /> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger.Actions> 
      </EventTrigger> 
     </Style.Triggers> 
    </Style> 

添加了整个样品。

<Window 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit" 
xmlns:uc="clr-namespace:WpfApplication10" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
x:Class="WpfApplication10.Window1" 
x:Name="Window" 
Title="Window1" mc:Ignorable="d"> 
<Window.Resources> 
    <DataTemplate x:Key="ItemTemplate1"> 
     <StackPanel> 
      <TextBlock Text="{Binding Property1}"/> 
      <Image Source="{Binding Property2}" HorizontalAlignment="Left" Height="64" Width="64"/> 
     </StackPanel> 
    </DataTemplate> 
    <Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}"> 
     <Setter Property="BitmapEffect"> 
      <Setter.Value> 
       <OuterGlowBitmapEffect GlowColor="Blue" GlowSize="5" /> 
      </Setter.Value> 
     </Setter> 
     <Style.Triggers> 
      <EventTrigger RoutedEvent="ListViewItem.MouseEnter"> 
       <EventTrigger.Actions> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.Opacity"        
          From="0.0" To="1.0" Duration="0:0:0.5" AutoReverse="False" SpeedRatio="2" /> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger.Actions> 
      </EventTrigger> 
      <EventTrigger RoutedEvent="ListViewItem.MouseLeave"> 
       <EventTrigger.Actions> 
        <BeginStoryboard> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetProperty="BitmapEffect.Opacity"        
          From="1.0" To="0.0" Duration="0:0:0.5" AutoReverse="False" SpeedRatio="2" /> 
         </Storyboard> 
        </BeginStoryboard> 
       </EventTrigger.Actions> 
      </EventTrigger> 
     </Style.Triggers> 
    </Style> 
</Window.Resources> 
<Grid DataContext="{Binding Source={StaticResource SampleDataSource1}}"> 
    <ListBox DataContext="{Binding Source={StaticResource SampleDataSource3}}" 
       ItemTemplate="{DynamicResource ItemTemplate1}" ItemsSource="{Binding Collection}" 
       ItemContainerStyle="{DynamicResource ListBoxItemStyle1}" > 
    </ListBox> 
</Grid> 

+0

感谢您的答复,但本作淡出整个的ListViewItem的。我想淡出并淡入ListViewItem的BitmapEffect的不透明属性! 我之前尝试过这种方式 Storyboard.TargetProperty =“BitmapEffect.Opacity” 但我再次得到相同的错误! – Jalal 2010-07-23 09:16:17

+0

我编辑了我的XAML,请检查。我不知道你使用的是什么位图效果。 – Ragunathan 2010-07-23 09:50:39

+0

谢谢,但是这个也出现错误!我正在使用OuterGlowBitmapEffect。 – Jalal 2010-07-23 10:03:57

相关问题