Ошибка при увеличении свойства непрозрачности с помощью DoubleAnimation - PullRequest
0 голосов
/ 23 июля 2010

У меня есть стиль для элемента управления ListViewItem:

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

1 Ответ

3 голосов
/ 23 июля 2010

Я пытался с 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>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...