0

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>

これが、mainWindowに長方形を描画しようとしたクラスコードスニペットです。

private UIElement container;

private Rect rect1 = new Rect();

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

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

それをどのように処理しますか?

4

1 に答える 1

1

ウィンドウにはコンテンツを1つしか含めることができないためContent、ウィンドウのプロパティを設定する必要があります。

于 2012-08-14T10:57:23.297 に答える