2011-01-12 103 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專業版),所以這不會是聞所未聞......