0
我想提請在C# 另一個階級一個矩形進我的主窗口從另一個類添加矩形在C#
<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>
這裏是我試圖繪製一個矩形我的類代碼段主窗口
private UIElement container;
private Rect rect1 = new Rect();
public TestPage(UIElement cont)
{
this.container = cont;
}
private void init()
{
this.container.Children.Add(rect1);
}
如何處理?
我GOOGLE了,但我不知道應該設置我的mainWindow的Content屬性值。任何提示? – bbklol 2012-08-14 11:05:55
@bbklol:Read this http://stackoverflow.com/questions/7884185/wpf-how-to-dynamically-add-controls-in-dynamically-created-wpf-window – 2012-08-14 11:08:52