1

I'd like to implement my own control for Windows Phone. The catch is, that I want to draw it myself - in regular WPF I'd simply override OnRender method and provide my own implementation. However, there is no OnRender method available on Windows Phone. What other options do I have?

What is not acceptable in my case is:

  • Drawing on bitmap in background and displaying it
  • Using vector shapes instead of raster drawing
Spook
  • 25,318
  • 18
  • 90
  • 167
  • A control with a Canvas as its ControlTemplate will do the trick. You will need to add elements under the Canvas.Children. Or you can check out WIN2D, it just extends Canvas with some awesome GDI calls like DrawLine, DrawCircle, etc. – Chubosaurus Software Dec 07 '14 at 14:29

1 Answers1

2

Since Windows.UI.Xaml doesn't have a raster graphics API the only options are to use vector graphics, to render into a bitmap and display that, or to interop to DirectX.

Microsoft's Win2D library at http://microsoft.github.io/Win2D (also see http://blogs.msdn.com/b/win2d/ ) exposes Direct2D through C# and is probably the best match for what you are looking for. It is a work in progress and provides most basic features, but if you need more you'll need to do the interop yourself.

The closest other option is to use a 3rd party library such as WriteableBitmapEx for a high level API to draw into a WriteableBitmap. You could extract the generated bitmap into an ImageBrush for display without an explicit Image control.

Rob Caplan - MSFT
  • 21,714
  • 3
  • 32
  • 54