Ok, I'm stumped. Why is this not rendering the square? (Note, I purposely used positive and negative coordinates so it would display regardless of the origin. Didn't know if the x/y were reversed, etc.)
public partial class Main : Window
{
StreamGeometry _cueGeometry;
Brush _cueBrush;
Pen _cuePen;
public Main()
{
InitializeComponent();
_cueGeometry = new StreamGeometry();
using (var geometryContext = _cueGeometry.Open())
{
geometryContext.BeginFigure(new Point( 40, 40), true, true);
geometryContext.LineTo (new Point( 40,-40), true, true);
geometryContext.LineTo (new Point(-40,-40), true, true);
geometryContext.LineTo (new Point(-40, 40), true, true);
}
_cueGeometry.Freeze();
_cueBrush = Brushes.AliceBlue;
_cuePen = new Pen(Brushes.Gray, 1);
_cuePen.Freeze();
}
protected override void OnRender(DrawingContext dc)
{
base.OnRender(dc);
dc.DrawGeometry(_cueBrush, _cuePen, _cueGeometry);
}
}
Update
I've noticed something else odd. If I move this code to a subclass of Panel with a red background, it renders the red background then renders a blue square with a gray border in front of it. (Note: it's not clipped to the bounds of the control which is how I can see all of that square.)
If however, I simply change the subclass to UserControl, the blue square with a gray border renders behind the red control. (Again, I can see this because I have clipping disabled.)
If finally I change it to a subclass of Control, I no longer get the red background and only get the blue square with a gray border. This I take it is because Control doesn't do any rendering on its own, but still doesn't explain why the background color is rendering over my drawing in a UserControl as opposed to the Panel. My guess is there's some element that's part of a template that's appearing in front of what's rendered, but I can't think what that would be.