shadeMe
shadeMe

Reputation: 716

Drawing Control Visual Elements onto a Rectangle

I've got a custom composite WPF control (AvalonEdit) in my application that I'd like to animate whenever its Text property is changed. What I intend to do is:

  1. Create a copy of the control's visual representation before the text is changed and paint it over a rectangle.
  2. Fade out the above rectangle, update the text property and fade in the control using the DoubleAnimation and Storyboard classes.

I've got #2 figured out but haven't got a clue about how I'd achieve #1. Any help would be appreciated.

Upvotes: 0

Views: 221

Answers (1)

ColinE
ColinE

Reputation: 70122

For (1) there are a couple of approaches that spring to mind:

  1. VisualBrush - A visual brush is a brush which is defined by a complex UI element. In other words, you can create a visual tree of elements and use this to create your brush. See the tutorial here. I think in your case you would have to define your UI twice, i.e. have an instance of your AvalonEdit control as the 'visual' for you VisualBrush, so perhaps not ideal

  2. WriteableBitmap - A writeable bitmap allows you to copy part of your UI into a bitmap where you can manipulate he pixel data. Whilst you do not need pixel-level manipulation it is still a convenient mechanism for cloning your UI. See this tutorial I wrote here.

Upvotes: 1

Related Questions