![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Possible bug in System.Windows.Application: Windows property I'm trying to access the collection of windows that an application contains using the Application.Windows property (returns a collection of type WindowsCollection). It seems that this collection only returns windows that are manually instantiated in C# code, but is missing the window set as the startupURI for the Application. Take the following example (I haven't displayed the window code here only the Application code, any generic window will do): MyApp.xaml: <Application x:Class="WindowScaler.MyApp" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" StartupUri="Window1.xaml" > <Application.Resources> </Application.Resources> </Application> MyApp.xaml.cs: public partial class MyApp : Application { private const int NUM_WINDOWS = 2; public MyApp() { // launch a number of windows for (int i = 0; i < NUM_WINDOWS; i++) { Window1 w = new Window1(); w.Name = "Test Window" + i; w.Show(); } // Print out window names foreach (Window w in Windows) { Console.WriteLine("Window Name: {1}", w.Name); } } } I'd expect this to output 3 window names to the console, one for the window listed in the Application's StartupUri and the additional windows created in the loop. However, this is what we get: Window Name: Test Window1 Window Name: Test Window2 The one from the StartupUri is missing. Is this a WPF bug or by design? Additionally, what if you don't really want to specify any startup URI window, because you want all of your windows created through C# in a consistent manner? Right now I get build errors when I don't provide the StartupURI... Thanks, Jason |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Possible bug in System.Windows.Application: Windows property Re: the first problem you describe (the startup window being missing from the Application's "Windows" collection), I believe the problem is the time at which you are examining the application's "Windows" property. I tested a simple application with a single window defined in XAML and declared to be the StartupUri of the application. If I examine the application's "Windows" property while the program's flow is in the Application's constructor method -- which is what your sample code is doing -- then indeed the "Windows" property does not include the startup window. But that's because the examination is being done too early... If I examine the application's "Windows" property when the flow has moved into the startup window's constructor method, then I *do* see the startup window present. So I believe this is strictly a timing issue -- the startup window is not yet present when the program's flow is still in the application's constructor. |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VISTA and Windows Installer ALLUSERS property.... | Superfreak3 | Vista security | 3 | 07-25-2007 08:55 AM |
| Subsclassing System.Windows.Application | Radek Cerny | Avalon | 1 | 05-23-2007 12:59 AM |
| System.DirectoryServices.DirectoryEntry & the accountExpires property | Clint Bergman | PowerShell | 8 | 04-30-2007 09:29 AM |
| Windows Application vs XAML Browser Application | Denis | Avalon | 0 | 04-20-2007 01:43 AM |
| Suggestion: Add a Basename property to System.IO.FileInfo | Alex K. Angelopoulos [MVP] | PowerShell | 5 | 06-25-2006 09:39 AM |