2013-04-26 43 views
1

這是我的代碼,它可以在Windows Phone 8模擬器上運行。淡入/淡出動畫導致ScrollViewer的內容模糊

  • XAML:

    <Grid x:Name="ContentPanel"> 
        <ScrollViewer> 
         <StackPanel> 
          <Button Content="Sample Content" Click="ButtonBase_OnClick"> 
           <Button.Style> 
            <Style TargetType="Button"> 
             <Setter Property="Width" Value="400"></Setter> 
             <Setter Property="Height" Value="100"></Setter> 
             <Setter Property="HorizontalContentAlignment" Value="Center"></Setter> 
             <Setter Property="VerticalContentAlignment" Value="Center"></Setter> 
             <Setter Property="Template"> 
              <Setter.Value> 
               <ControlTemplate TargetType="Button"> 
                <Grid> 
                 <Border CornerRadius="10,10,10,10" 
                   Background="{StaticResource PhoneAccentBrush}" 
                   BorderBrush="#FF000000" BorderThickness="1,1,1,1" 
                   x:Name="border" RenderTransformOrigin="0.5,0.5"> 
                  <Border.RenderTransform> 
                   <TransformGroup> 
                    <ScaleTransform /> 
                    <SkewTransform /> 
                    <RotateTransform /> 
                    <TranslateTransform /> 
                   </TransformGroup> 
                  </Border.RenderTransform> 
                  <ContentPresenter x:Name="contentPresenter" 
                       ContentTemplate="{TemplateBinding ContentTemplate}" 
                       VerticalAlignment="Center" 
                       HorizontalAlignment="Center" /> 
                 </Border> 
                </Grid> 
               </ControlTemplate> 
              </Setter.Value> 
             </Setter> 
            </Style> 
           </Button.Style> 
          </Button> 
          <TextBlock TextWrapping="Wrap"> 
           Lorem ipsum Pariatur sint occaecat sunt sint do labore adipisicing 
           eiusmod incididunt culpa laborum consequat magna dolor labore sunt sed 
           ullamco anim adipisicing do pariatur ea esse qui sint magna in voluptate 
           Duis id ut anim id. 
          </TextBlock> 
         </StackPanel> 
        </ScrollViewer> 
    </Grid> 
    
  • C#:

    private void ButtonBase_OnClick(object sender, RoutedEventArgs e) 
    { 
        var storyb = new Storyboard(); 
        Duration Show_Duration = new Duration(new TimeSpan(0, 0, 0, 0, 450)); 
        DoubleAnimation m_OpacityAni = new DoubleAnimation(); 
        m_OpacityAni.Duration = Show_Duration; 
        m_OpacityAni.From = 1.0; 
        m_OpacityAni.To = 0.0; 
        m_OpacityAni.AutoReverse = true; 
    
        storyb.Children.Add(m_OpacityAni); 
    
        Storyboard.SetTarget(m_OpacityAni, ContentPanel); 
        Storyboard.SetTargetProperty(m_OpacityAni, new PropertyPath("(UIElement.Opacity)")); 
    
        storyb.Begin(); 
    } 
    

眼下,因爲內容的高度大於命名爲 「的ContentPanel」 網格小,所以當動畫開始,所有內容將淡入/淡出。但是,如果我爲了使ScrollViewer更長(使其可滾動)而重複該TextBlock,然後再次運行動畫。這些內容將顯示模糊,直到它結束。

如果我刪除了ScrollViewer標籤,則所有內容都將顯示爲清晰。

雖然它不會導致一些不良的副作用,但我想知道它爲什麼會這樣顯示。

期待您的回答。謝謝!

回答

1

也許它在動畫期間設置ScrollViewer.CacheMode = CacheMode.BitmapCache

+0

也許當我在這個控件上使用動畫時,它使用裏面的BitmapCache。所以看起來很模糊。 – Eddie 2014-03-19 09:11:53