我有一个带有样式的Listbox,包括带有样式的Listboxitem。我正在尝试创建一个将不透明度从0更改为1的动画,以使项目显示在列表中。我设法用下面的代码来做到这一点:ListBoxItem动画和不透明度
<Style x:Key="ListBoxStyle1" TargetType="ListBox">
<Setter Property="Foreground" Value="#FF393C3F" />
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Border Name="Border" Background="{x:Null}" BorderBrush="Black" BorderThickness="0" Padding="0">
<ItemsPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ListBoxItemStyle1" TargetType="ListBoxItem">
<Setter Property="Opacity" Value="0" />
<Setter Property="Height" Value="16" />
<Setter Property="VerticalContentAlignment" Value="Bottom" />
<Setter Property="VerticalAlignment" Value="Bottom" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="Border" Padding="10,1,0,0" Background="{x:Null}">
<ContentPresenter VerticalAlignment="Center" SnapsToDevicePixels="True" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Border" Property="Background" Value="{StaticResource arrow}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="#FF828689" />
</Trigger>
<Trigger Property="IsVisible" Value="true">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:0.4" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
,因为它应该(除此之外,我想有更多的时间对当前和下一个项目的动画之间传递的开始,但它与不透明问题的事情的作品。 。一切都可以被设置为透明,背景和所有我使用所选项目透明的PNG刷
的问题是不透明度动画,最好看到底部的图片:
这是动画中间的截图(当时listboxitems的不透明度为0.8),并且您可以清楚地看到围绕所有文本的白色背景。它在第一个选择的项目中更加明显,因为它使用透明的.png。当动画完成并且不透明度为1.0时,此背景会神奇地消失。
如何解决这个问题?我忘了设置任何背景吗?
谢谢你的帮助!
编辑:
我加入我的列表框声明:
<ListBox Height="239" HorizontalAlignment="Left" Margin="0,0,0,0" Name="listBox1" VerticalAlignment="Top" Width="145" Background="{x:Null}" FontWeight="Black" FontSize="8" BorderBrush="{x:Null}" SnapsToDevicePixels="True" BorderThickness="0" ItemContainerStyle="{StaticResource ListBoxItemStyle1}" Style="{StaticResource ListBoxStyle1}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VerticalAlignment="Top" Background="{x:Null}" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
而且另一个问题是:如何延迟,每一个ListBoxItem将与几毫秒的延迟在下单前会显示动画?
谢谢你的一切帮助。
你可以添加列表框声明吗?我已将这种风格插入到我的一个程序中,并且没有您遇到的问题。 – 2011-01-12 19:45:56
谢谢你的回答,斯科特。我已经添加了我的列表框声明。我已经做了更多的测试,并且绝对不依赖于系统。问题出在我的应用程序或WPF中。甚至不需要为这个问题制作动画。第二个列表框项目具有不同于0或1.0的样式设置的不透明度,它以白色背景呈现。即使是没有背景图片的列表框项目。我的文章中的图片呈现在列表框的不透明度为0.8。 – Legoless 2011-01-15 21:00:52