Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Reference a xaml window from a WinFX Custom Control Library ?

 
 
Old 02-24-2006   #1 (permalink)
Peter Fitzgibbons


 
 

Reference a xaml window from a WinFX Custom Control Library ?

Hello all,

I wish to contain all the xaml/code for my project within a custom control
library (DLL). The exe project will contain only a MyApp.xaml that runs the
first window of the application from teh DLL.

How can I accomplish this?

Also, the eventual intention of this is testing via NUnit w/
System.Windows.Automation from another DLL that is the NUnit target library
(Test Runner). What is required in this scenario to setup the test target
(xaml window) for automation control and inspection?

Thank you all for your advice and support!


My System SpecsSystem Spec
Old 02-24-2006   #2 (permalink)
Drew Marsh


 
 

Re: Reference a xaml window from a WinFX Custom Control Library ?

> Hello all,
>
> I wish to contain all the xaml/code for my project within a custom
> control library (DLL). The exe project will contain only a MyApp.xaml
> that runs the first window of the application from teh DLL.
>
> How can I accomplish this?


You need to just control the application initialization yourself.

1. Don't set StartupUri.
2. Override Application::OnStartup[1]
3. Instantiate the Window class from the control library and pass it to Application::Run[2].

> Also, the eventual intention of this is testing via NUnit w/
> System.Windows.Automation from another DLL that is the NUnit target
> library (Test Runner). What is required in this scenario to setup the
> test target (xaml window) for automation control and inspection?


I don't have an answer to this one since I haven't done enough with automation
yet. Basically though you'll need to make sure there's a Dispatcher running
for the thread (implies STA) that NUnit has created. Once there's a Dispatcher
I think you should just be able to create a window instance and go to town.

HTH,
Drew

[1] http://windowssdk.msdn.microsoft.com...asp?frame=true
[2] http://windowssdk.msdn.microsoft.com...1_ac53f552.asp
___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
Old 02-24-2006   #3 (permalink)
Drew Marsh


 
 

Re: Reference a xaml window from a WinFX Custom Control Library ?

I wrote:

> 3. Instantiate the Window class from the control library and pass it
> to Application::Run[2].


Sorry, just thought about this some more and realized it's bad advice because
the application's already had its Run called by the Main method that's provided
by the MyApp.g.cs. Do this as the third step instead:


protected override OnStartup(StartingUpEventArgs args)
{
Window mainWindow = new YourWindowFromTheLibrary();

this.MainWindow = mainWindow;
mainWindow.Show();

base.OnStartup(e);
}

HTH,
Drew


My System SpecsSystem Spec
Old 02-24-2006   #4 (permalink)
Peter Fitzgibbons


 
 

Re: Reference a xaml window from a WinFX Custom Control Library ?

HI Drew,

I got this working... that is, unit-test XAML windows with NUnit. The
result is an adventure into System.Threading and a firm grasp on the
requirements of Nunit (runs everything on an MTA thread) and WPF (Window runs
on STA thread).

Here's my post :
http://fitzgibbons.info/articles/200...dow-with-nunit



"Drew Marsh" wrote:

> > Hello all,
> >
> > I wish to contain all the xaml/code for my project within a custom
> > control library (DLL). The exe project will contain only a MyApp.xaml
> > that runs the first window of the application from teh DLL.
> >
> > How can I accomplish this?

>
> You need to just control the application initialization yourself.
>
> 1. Don't set StartupUri.
> 2. Override Application::OnStartup[1]
> 3. Instantiate the Window class from the control library and pass it to Application::Run[2].
>
> > Also, the eventual intention of this is testing via NUnit w/
> > System.Windows.Automation from another DLL that is the NUnit target
> > library (Test Runner). What is required in this scenario to setup the
> > test target (xaml window) for automation control and inspection?

>
> I don't have an answer to this one since I haven't done enough with automation
> yet. Basically though you'll need to make sure there's a Dispatcher running
> for the thread (implies STA) that NUnit has created. Once there's a Dispatcher
> I think you should just be able to create a window instance and go to town.
>
> HTH,
> Drew
>
> [1] http://windowssdk.msdn.microsoft.com...asp?frame=true
> [2] http://windowssdk.msdn.microsoft.com...1_ac53f552.asp
> ___________________________________
> Drew Marsh
> Chief Software Architect
> Mimeo.com, Inc. - http://www.mimeo.com
> Microsoft C# / WPF MVP
> Weblog - http://blog.hackedbrain.com/
>
>
>

My System SpecsSystem Spec
 

Thread Tools



Vista Forums 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 Ltd

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