別のWPFウィンドウからWPFリストボックス(ブレンドで作成されたウィンドウ)にアイテムを追加する方法を知っている人はいますか?
私は次のコードを持っています
mainpage mp = new mainpage();
mp.listbox1.Items.Add(namebox.Text);
君たちありがとう
2 つのソリューション:
パラメーターを使用してコンストラクターを作成し、それらをコンストラクターに追加します
メインページ mp = 新しいメインページ (namebox.Text);
public mainpage(string newItem){ this.listbox1.Items.Add(namebox.Text); }
Application
-namespace で-classを使用できますSystem.Windows
。使用する
System.Windows.Application app = System.Windows.Application.Current;
System.Windows.WindowCollection wincol = app.Windows;
//iterate through collection and find your window
もちろん、通常はすべてのウィンドウが独自のスレッドで作成されるため、スレッド化に注意する必要があります。詳細については、 MSDNを参照してください。