全部博文(105)
分类: 嵌入式
2012-04-14 12:32:14
2. Open an Existing instance of a Window instead of a new Instance
Picture the scene, your creating an address book application and to add a new contact you have set it to bring up a new Add Contact Window. Once you finish you application and release it out in the wild you get a angry email from Timmy, a frustrated user. For some reason hes got 53 instances of the Add Contact Window open!
Now to keep poor Timmy happy what you need to do is before opening a new instance of your Window you want to make sure that none are already open.
And using the same magic as above you do the following:
foreach(Window win in App.Current.Windows)
What we are doing is looping through the collection of Windows within your application and then checking if any of the windows are of the type we are wanting to open. If it does find one with the same type it will show the Window to the screen, if not it will do nothing.
To quote “Simples”.