0

I want to draw a rect from another class in c# into my mainWindow

<Window x:Class="MyApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Name="mainWindow" Height="768" Width="1366" >
</Window>

Here is my Class code snippet which I tried to draw a rect to mainWindow

private UIElement container;

private Rect rect1 = new Rect();

public TestPage(UIElement cont) 
{        
    this.container = cont;
}

private void init()
{
    this.container.Children.Add(rect1);
}

How to handle it?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
bbklol
  • 45
  • 5

1 Answers1

1

A Window can have only one content so you have to set Content property of Window.

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
  • I googled but I dont know which value the Content property of my mainWindow should be set. Any hint? – bbklol Aug 14 '12 at 11:05
  • @bbklol: Read this http://stackoverflow.com/questions/7884185/wpf-how-to-dynamically-add-controls-in-dynamically-created-wpf-window – Nikhil Agrawal Aug 14 '12 at 11:08