Sure there is a sample in the last entry of this forum post:
Some notes about the boundary determination error:
- it is usually because of the boundary detection algorithm trying to determine the outline of an object you are using. This algorithm works by tracing a path around the pixels in the object
- your visual tree _has_ to be drawn to the screen in order for the boundary detection to work! This is because it uses the VisualTreeHelper class.
- if you have ONE OR MORE instances of your physics object inside your game Canvas XAML at start time, the boundary will be determined and CACHED by the physics controller. So that subsequent programmatic ads will used the cached boundary for performance
(the trace takes some time!)
- If you DO NOT have ONE OR MORE instances of the physics object inside your game Canvas XAML at start time, you will need to delay the AddPhysicsBody calls until after the Visual Tree is drawn. I often use a very short duration (500 ms) Storyboard to make
sure everything is drawn to the screen so that the VisualTreeHelper can do a HitTest.
- make sure you don't have any stray pixels sitting around outside the image's shape, because this can throw off the boundary detection algorithm.
- you need to make sure everything is in a Canvas (no Grids) and make sure the Canvas is located at x,y = 0,0 in your visual tree (You can change this after the Initialized event raised by the PhysicsController. (Admittedly this is a bit touchy!)
So no Game Canvas inside a Grid - but you can certainly use overlays on top of your game Canvas for score, etc.
Also, there are several posts on Adding Physics Behaviors Programmatically -