Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Possible bug in System.Windows.Application: Windows property

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
Jason Dolinger
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 SpecsSystem Spec
Old 01-10-2006   #2 (permalink)
D. F. Sklar
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 SpecsSystem Spec
Closed Thread

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51