将项添加到Owner Window ListBox

时间:2013-04-06 20:36:25

标签: c# properties listbox window

我实际上是在向所有者窗口中的ListBox添加一个元素

我尝试使用Owner Windows属性,但我无法访问我的ListBox。

Window parent = this.Owner;
parent.toto.Items.Add();

我还尝试在我的所有者窗口类中添加一个公共属性(并在set方法中添加项目),但我也无法访问它。

2 个答案:

答案 0 :(得分:1)

Owner属性的类型为Window。编译器不知道它实际上是您创建的类型。如果您执行演员表,并且ListBox 公开曝光,您应该可以访问它:

YourWindowType parent = (YourWindowType)this.Owner;
parent.toto.Items.Add(...);

答案 1 :(得分:0)

尝试

  

Window parent = this.ActiveForm;