2017-06-29 27 views
2

Windows UI開発ラボのサンプルギャラリーでサンプルを使用しています。私はShyHeaderのサンプルを使ってアプリケーションを作成しましたが、全く同じコードを使用していませんが、実際には自分の必要に応じてサンプルを編集しました。 私の質問は、式ノードを使用してスクロールビューアに対応して特定のXAML要素をフェードインさせる方法です。スクロールビューアで要素をフェードアウトすることができます。私は不透明度0から不透明度1の要素をフェードインできません。 ここは私のコードです。uwpアニメーションの表現ノードがフェードアウトする

<ScrollViewer x:Name="MyScrollViewer"> 
    <Grid> 
     <local:MyAdaptiveView Margin="0,300,0,0" 
        x:Name="AllVideosGridView"/> 
     <Grid x:Name="Header" Height="300" VerticalAlignment="Top"> 
      <FlipView x:Name="MainFlipView" 
      </FlipView> 
      <Grid Background="Blue" Height="150" VerticalAlignment="Bottom" Opacity="0.5" Name="FrontGrid"> 

      </Grid> 
     </Grid> 
    </Grid> 
</ScrollViewer> 

ページロード方法

コードの唯一の重要な部分にのみ、この方法の一番最後にある、最後の4、5行が、私は要素をフェードアウトすることができる午前見ることができます1- progresNodeを実行しますが、0+ progressNodeを実行して別の要素(frontVisual)をフェードインしようとしましたが、スクロールしてもfrontVisualは実際には0の不透明度のままです。 プライベートvoid ShyView_Loaded(オブジェクト送信者、RoutedEventArgs e) { // MyScrollViewerからのスクロール値を含むPropertySetを取得します。 _scrollerPropertySet = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(MyScrollViewer); _compositor = _scrollerPropertySet.Compositor;私が実際にしたい

 // Create a PropertySet that has values to be referenced in the ExpressionAnimations below 
     _props = _compositor.CreatePropertySet(); 
     _props.InsertScalar("progress", 0); 
     _props.InsertScalar("clampSize", 150); 
     _props.InsertScalar("scaleFactor", 0.7f); 

     // Get references to our property sets for use with ExpressionNodes 
     var scrollingProperties = _scrollerPropertySet.GetSpecializedReference<ManipulationPropertySetReferenceNode>(); 
     var props = _props.GetReference(); 
     var progressNode = props.GetScalarProperty("progress"); 
     var clampSizeNode = props.GetScalarProperty("clampSize"); 
     var scaleFactorNode = props.GetScalarProperty("scaleFactor"); 

     // Create a blur effect to be animated based on scroll position 
     var blurEffect = new GaussianBlurEffect() 
     { 
      Name = "blur", 
      BlurAmount = 0.0f, 
      BorderMode = EffectBorderMode.Hard, 
      Optimization = EffectOptimization.Balanced, 
      Source = new CompositionEffectSourceParameter("source") 
     }; 

     var blurBrush = _compositor.CreateEffectFactory(
      blurEffect, 
      new[] { "blur.BlurAmount" }) 
      .CreateBrush(); 

     blurBrush.SetSourceParameter("source", _compositor.CreateBackdropBrush()); 

     // Create a Visual for applying the blur effect 
     _blurredBackgroundImageVisual = _compositor.CreateSpriteVisual(); 
     _blurredBackgroundImageVisual.Brush = blurBrush; 
     _blurredBackgroundImageVisual.Size = new Vector2((float)Header.ActualWidth, (float)Header.ActualHeight); 

     // Insert the blur visual at the right point in the Visual Tree 
     ElementCompositionPreview.SetElementChildVisual(Header, _blurredBackgroundImageVisual); 

     // Create and start an ExpressionAnimation to track scroll progress over the desired distance 
     ExpressionNode progressAnimation = EF.Clamp(-scrollingProperties.Translation.Y/clampSizeNode, 0, 1); 
     _props.StartAnimation("progress", progressAnimation); 

     // Create and start an ExpressionAnimation to animate blur radius between 0 and 15 based on progress 
     ExpressionNode blurAnimation = EF.Lerp(0, 15, progressNode); 
     _blurredBackgroundImageVisual.Brush.Properties.StartAnimation("blur.BlurAmount", blurAnimation); 

     // Get the backing visual for the header so that its properties can be animated 
     Visual headerVisual = ElementCompositionPreview.GetElementVisual(Header); 

     // Create and start an ExpressionAnimation to clamp the header's offset to keep it onscreen 
     ExpressionNode headerTranslationAnimation = EF.Conditional(progressNode < 1, 0, -scrollingProperties.Translation.Y - clampSizeNode); 
     headerVisual.StartAnimation("Offset.Y", headerTranslationAnimation); 

     // Create and start an ExpressionAnimation to scale the header during overpan 
     ExpressionNode headerScaleAnimation = EF.Lerp(1, 1.25f, EF.Clamp(scrollingProperties.Translation.Y/50, 0, 1)); 
     headerVisual.StartAnimation("Scale.X", headerScaleAnimation); 
     headerVisual.StartAnimation("Scale.Y", headerScaleAnimation); 

     //Set the header's CenterPoint to ensure the overpan scale looks as desired 
     headerVisual.CenterPoint = new Vector3((float)(Header.ActualWidth/2), (float)Header.ActualHeight, 0); 

     // Get the backing visual for the photo in the header so that its properties can be animated 
     Visual photoVisual = ElementCompositionPreview.GetElementVisual(MainFlipView); 

     // Create and start an ExpressionAnimation to opacity fade out the image behind the header 
     ExpressionNode imageOpacityAnimation = 1 - progressNode; 
     photoVisual.StartAnimation("opacity", imageOpacityAnimation); 

     // Get the front visual for the photo in the header so that its properties can be animated 
     Visual frontVisual = ElementCompositionPreview.GetElementVisual(FrontGrid); 

     // Create and start an ExpressionAnimation to opacity fade out the image behind the header 
     ExpressionNode imageOpacityAnimation2 = 0 + progressNode; 
     frontVisual.StartAnimation("opacity", imageOpacityAnimation2); 
    } 

行動は、私がその後、スクロールダウンしたときにFlipViewがフェードアウトすべきと私はトップまでスクロールすると、それはフェードインする必要があり、完全に作業しているが、それに伴ってということですFrontGridを正反対にしたい、すなわち:スクロールダウン時にフェードインし、スクロールアップ時にフェードアウトする。事前に

おかげで

答えて

2

あなたの表現はOKに見えます。

Opacityは、OpacityVisualであることを示しています。ただし、Opacity0.5に設定されています。FrontGrid XAMLはUIElementです。そうすることで、コンポジションの不透明度の表現アニメーションが解除されます。

修正は簡単です - 右InitializeComponent後にFrontGridVisualを取得してみて、そこにそのOpacity0.5に設定(すなわちfrontVisual.Opacity = 0.5)の代わりにXAMLでそれを設定します。


あなたが原因XAML組成相互運用機能の動作の変更に、記念日のアップデートから始まる「奇妙な」行動のこの種を見ることができます。

詳しくは、official documentをお読みください。

つまり、XAMLはCompositionがOpacityを変更したかどうかを知りませんが、最後に設定されたとおりに0.5であると考えています。したがって、オーバーライドしてアニメーションを失敗させようとします。これは、OffsetSizeなどのいくつかのプロパティにも発生します。

私のアドバイスは、あなたが行く場合は、構図、すべての方法で組成を行ってみてください。 :)

関連する問題