How to draw on a Window in WPF (best practice)?

前端 未结 5 470
无人及你
无人及你 2021-02-01 04:01

I am trying to write a small interactive game-like application, where I need to have a Draw method that\'s gonna draw on screen, but can\'t figure out how to struct

5条回答
  •  情歌与酒
    2021-02-01 04:39

    I preffer to use OnRender method like in this example:

    protected override void OnRender(DrawingContext drawingContext)
    {
        base.OnRender(drawingContext);
         drawingContext.DrawRectangle(null, new Pen(Brushes.Black, 2), new Rect(0, 0, ActualWidth, Height));
    }
    

提交回复
热议问题