首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用DoubleAnimation增加不透明度属性时出错

使用DoubleAnimation增加不透明度属性时出错
EN

Stack Overflow用户
提问于 2010-07-23 14:32:32
回答 1查看 1K关注 0票数 0

我有一个ListViewItem控件的样式:

代码语言:javascript
复制
<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上时,项目的边框慢慢出现,当鼠标离开它时,边框效果消失,但当鼠标离开项目时,我得到了这个错误:

代码语言:javascript
复制
Cannot resolve all property references in the property path 'BitmapEffect.Opacity'. Verify 
that applicable objects support the properties. 

请注意,当我只使用路由到ListViewItem.MouseEnter的第一个EventTrigger时,程序工作正常!但是视野不是很好!

我在用OuterGlowBitmapEffect!

代码语言:javascript
复制
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="BitmapEffect">
                        <Setter.Value>
                            <OuterGlowBitmapEffect GlowColor="SkyBlue" GlowSize="20" />
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Foreground" Value="Black" />
                </Trigger>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-07-23 16:46:24

我正在尝试使用BitmapEffect,它和上面的代码一样工作得很好。

代码语言:javascript
复制
<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>

添加了整个样本。

代码语言:javascript
复制
<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>

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3315811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档