【问题标题】:Add Rect from another class in c#在 c# 中从另一个类添加 Rect
【发布时间】:2013-02-24 06:12:57
【问题描述】:

我想从 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>

这是我的类代码 sn-p,我试图在 mainWindow 中绘制一个矩形

private UIElement container;

private Rect rect1 = new Rect();

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

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

如何处理?

【问题讨论】:

    标签: c# wpf


    【解决方案1】:

    一个窗口只能有一个内容,所以你必须设置窗口的Content属性。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多