简体   繁体   English

将项目添加到所有者窗口列表框

[英]Add item to Owner Window ListBox

i'm actually trying to do add an element to an ListBox wich is in the Owner Window 我实际上是想在所有者窗口中向ListBox添加元素

I tried to use the Owner Windows property but i can't access my ListBox. 我试图使用“所有者Windows”属性,但无法访问列表框。

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

I also tried to add a public property in my Owner Window class (and add the item on the set method), but i can't access it neither. 我还尝试在Owner Window类中添加一个公共属性(并在set方法上添加该项目),但是我也无法访问它。

The type of the Owner property is Window . Owner属性的类型是Window The compiler doesn't know that it is actually the type you created. 编译器不知道它实际上是您创建的类型。 If you perform a cast, and your ListBox is exposed publicly , you should be able to access it: 如果执行强制转换,并且ListBox 公开公开 ,则应该可以访问它:

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

尝试

Window parent = this.ActiveForm;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM