title: DrawingContext DrawGeometry on Canvas (wpf)
body: <p>I try to programmatically draw a rectangle with rounded corners in my WPF project. I'm pretty new to WPF and trying to figure out how drawing works since it's much different than WinForms. I'm using <a href="http://wpftutorial.net/DrawRoundedRectangle.html" rel="nofollow noreferrer">>this&lt;</a> link for the rounded rectangle method (my method is the same as on that website). Here is my code:</p>
  
  <pre><code>Rect rect = new Rect();
  rect.Width = Width - BorderSize;
  rect.Height = Height - BorderSize;
  
  DrawingVisual drawingVisual = new DrawingVisual();
  using (var draw = drawingVisual.RenderOpen())
  {
      DrawRoundedRectangle(draw, new SolidColorBrush(Color.FromRgb(0, 0, 0)),
      new Pen(new SolidColorBrush(Color.FromRgb(0, 0, 0)), BorderSize), rect, new CornerRadius(5, 5, 5, 5));
  }
  
  ContentPresenter content = new ContentPresenter();
  content.Content = drawingVisual;
  previewcanvas.Children.Add(content);
  </code></pre>
  
  <p>This is my output on the canvas:</p>
  
  <p><a href="https://i.stack.imgur.com/pvTP9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pvTP9.png" alt="enter image description here"></a></p>
  
  <p>Not really what I'm expecting ;) there shouldn't be any text in there to begin with.</p>
  
  <p>Hope someone can help me to draw the rounded rectangle!</p>
  
  <p><strong>edit</strong></p>
  
  <p>Some extra info, I need to be able to set each individual corner.</p>