2016-09-06 20 views
2

ストーリーボードを使用してTextBlockをズームインすると、ズーミング中にピクセル化され、完了時にのみレンダリングされます。UWPでTextBlockのスケールをアニメーション化する方法

<DoubleAnimationUsingKeyFrames Storyboard.TargetName="TextBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1.5"/> 

各フレームにTextBlockが再レンダリングされる方法はありますか?

答えて

2

それはもうTextBlockのではないのですけれども、私は解決策を見つけましたが、私のためにそれが働いた:

private void CreateText(string text) 
    { 
     _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; 
     CreateDevice(); 

     _spriteTextVisual = _compositor.CreateSpriteVisual(); 
     _spriteTextVisual.Size = new Vector2(512, 512); 

     _drawingTextSurface = _graphicsDevice.CreateDrawingSurface(new Size(512, 512), DirectXPixelFormat.B8G8R8A8UIntNormalized, DirectXAlphaMode.Premultiplied); 

     using (var ds = CanvasComposition.CreateDrawingSession(_drawingTextSurface)) 
     { 
      ds.Clear(Colors.Transparent); 
      ds.DrawText(text, new Rect(0, 0, 512, 512), Colors.Black, new CanvasTextFormat 
      { 
       FontSize = 32, 
       FontWeight = FontWeights.Light, 
       VerticalAlignment = CanvasVerticalAlignment.Top, 
       HorizontalAlignment = CanvasHorizontalAlignment.Center, 
       LineSpacing = 32 
      }); 
     } 

     _surfaceTextBrush = _compositor.CreateSurfaceBrush(_drawingTextSurface); 

     _spriteTextVisual.Brush = _surfaceTextBrush; 

     ElementCompositionPreview.SetElementChildVisual(this, _spriteTextVisual); 
    } 

    private void CreateDevice() 
    { 
     _device = CanvasDevice.GetSharedDevice(); 
     _device.DeviceLost += Device_DeviceLost; 

     if (_graphicsDevice == null) 
     { 
      _graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(_compositor, _device); 
     } 
     else 
     { 
      CanvasComposition.SetCanvasDevice(_graphicsDevice, _device); 
     } 
    } 

    private async void Device_DeviceLost(CanvasDevice sender, object args) 
    { 
     _device.DeviceLost -= Device_DeviceLost; 
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, CreateDevice); 
    } 

ちょうど最大規模の大きさのこのテキストをしなければなりません。

0

これは、非常によく似た質問によると、 - see this answer by Jerry Nixonであるようです。

明らかに、アニメーションがスムーズであることを保証するために、各フレームでフォントを完全にレンダリングすることは費用がかかるためです。

あなたはおそらくこれを克服することができる唯一の方法は、Viewbox要素内TextBlockをラップし、ViewboxHeightプロパティをスケーリングすることです。ただし、これは自動的には機能しません。また、DoubleAnimationUsingKeyFrames要素にEnableDependentAnimation="True"を追加する必要があります。残念ながら、このアプローチでは各フレームのレイアウトが更新されるため、非常に不快感を感じます。

関連する問題