views:

62

answers:

1

Hi every body! 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 item 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>
+2  A: 

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>

Ragunathan
Thanks for reply but this make fade out whole of ListViewItem. I want to just fade out and fade in ListViewItem's BitmapEffect's Opacity property!I try this way before for Storyboard.TargetProperty="BitmapEffect.Opacity"but i get same error again!
Jalal Amini
I have edited my XAML, pls check. I don't know what bitmapeffect you are using.
Ragunathan
Thank you, but this one rise error too! I'm using OuterGlowBitmapEffect.
Jalal Amini
I have added the sample xaml. I am using Blend sample source data.
Ragunathan
Thank you again! I try your code in separate project and it works fine, I think my problem is something else! I check my code again! but it's very strange!!!
Jalal Amini