2011-01-12 99 views
2

我有一个带有样式的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刷

的问题是不透明度动画,最好看到底部的图片:

Screenshot

这是动画中间的截图(当时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将与几毫秒的延迟在下单前会显示动画?

谢谢你的一切帮助。

+0

你可以添加列表框声明吗?我已将这种风格插入到我的一个程序中,并且没有您遇到的问题。 – 2011-01-12 19:45:56

+0

谢谢你的回答,斯科特。我已经添加了我的列表框声明。我已经做了更多的测试,并且绝对不依赖于系统。问题出在我的应用程序或WPF中。甚至不需要为这个问题制作动画。第二个列表框项目具有不同于0或1.0的样式设置的不透明度,它以白色背景呈现。即使是没有背景图片的列表框项目。我的文章中的图片呈现在列表框的不透明度为0.8。 – Legoless 2011-01-15 21:00:52

回答

0

我已经解决了这个问题。问题是在代码中我重写了窗口的AllowTransparency标志。现在它的工作原理应该如此。如果有人会遇到类似的问题。

0

这可能是一个依赖于系统的渲染异常,我试过这种风格(只能使用我自己选择的项目图像,也是一个透明的PNG),它的工作很好。
在设置为Rectangle S中Fill财产矿山图像的一个应用是古怪拉长对我的一台计算机(其中甚至有相同的操作系统,Win7专业版),所以这不会是闻所未闻......