开发者

Error while increasing Opacity property using DoubleAnimation

开发者 https://www.devze.com 2023-01-08 07:11 出处:网络
I have a style for a ListViewItem control: <EventTrigger RoutedEvent=\"ListViewItem.MouseEnter\">

I have a style for a ListViewItem control:

<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>

I want to when mouse is over a ListViewItem, border of i开发者_JAVA技巧tem appearing slowly and when mouse leave it, border effect disappear, But i get this error when mouse goes to leave item:

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

Note that when i use only first EventTrigger which routed to ListViewItem.MouseEnter, program works correct! but it has not a good view!

I'm using 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>


I was trying with BitmapEffect, it is working fine as your above code.

<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>

Added Whole sample.

<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

精彩评论

暂无评论...
验证码 换一张
取 消