Friday, June 27, 2008

Making Silverlight Run As an EXE

well sort of.

So I've seen a few things like this: http://www.codeplex.com/SilverlightDesktop and thought I would see how easy it was... turns out to be 'super' simple...

Silverlight is designed to work inside a web browser. That being the case it is also not a ‘desktop’ or exe application. This ‘hack’ then allows us to take Silverlight applications and make them into exe’s. It works great however there are a few issues to keep in mind. One issue is that as shown here the exe won’t run on a 64 bit machine unless you get the 32bit IE engine running in the context of the control we will show. Also Silverlight still needs to be installed on the box and the one small detail about this only working on a windows machine but otherwise works well. The other major down sides is that a lot of things dependent on script injection or cross domain issues will in fact be ‘issues’ but you can work around that.

To start we just need to create a new project in Visual Studio. From the new project window we want to select a Windows Forms Application under windows (under the language of your choice). Once we do this we should get a blank Form 1. You can change the setting or set other values as you like. To get our Silverlight application running we need to add a folder that contains an HTML page and XAP that works from any local path. For example in our first project we could copy the output from our debug folder and call it good.

Once you drag a Silverlight application folder into our project we need to select on each item such as the HTML page and XAP files. In the properties pain of Visual Studio for each item there is a setting called ‘Copy to Output Directory.’ We need to change this setting for everything our Silverlight application depends on to ‘Copy always’.

Now that all the resources are present we need to start adding to the ‘Form’. Basically what we are going to do is add a web browser control that hosts the IE rendering engine that will load our Silverlight application in a web page running locally in an exe. In the tool box on the left side of visual studio under the tap ‘Common Controls’ drag the control onto the form on the design surface. Then resize the form and set any other properties you might want to set (ie: add an icon, or change title etc).

Right click on the form and select ‘View Code’ and add the following code:

string MyPath = Application.StartupPath + "\\[folder of Silverlight App]\\[Some Page].html";

webBrowser1.Navigate(MyPath);

The first line gets the path to our page that has the code to load the XAP for our application. Now then we pass this value into a call to the Navigate method on the web browser control. If you rename it the control name will be different but the sample above is the default. Compile and run the application and you will get your Silverlight application running in a win 32 window. If you wanted to be industrious you get build this in a VB 6 or C++ app doing the same kind of thing and even embed all the resources into the exe or build a custom installer etc and have this running on just about any windows platform with Silverlight even without .NET.

Thursday, June 26, 2008

Control Library on Codeplex

I started a code plex project on code plex... dah... that has a Silverlight control library solution with items from the forth coming book. right now I only did unit tests for 7 of the controls namely multi panel and some of the other panels and then mouse wheel support and browser history control etc. Robby's animating panel base (notstatic.com) from Mike H's blog (blogs.msdn.com/mharsh/). download the dll free at:

http://www.codeplex.com/HackingSilverlight

Wednesday, June 18, 2008

google command line...

ok so this one isnt' exactly a silverlight related posted but it is very cool. :) some one with clearly to much time on their hands implemented a web page that behaves like a console app (command line shell sort of thing) ... check it out at:

http://goosh.org/

Thursday, June 12, 2008

Another Radial Panel

A few weeks back I did a post(s) on panels using Robby's animating panel base including a Radial panel. Jobi a friend of mine did a post on his radial panel he wrote so I thought I would share that with everyone. Jobi's post gets more into explaining the math where I just showed so I thought it would be interesting if your into Silverlight Panels.

http://jobijoy.blogspot.com/2008/04/simple-radial-panel-for-wpf-and.html

Wednesday, June 11, 2008

DR. WPF on Pixel8

for those that know dr. WPF. good guy I might add not that I know is super secret identity or anything... check out the pod cast at:

http://pixel8.infragistics.com/#Episode:9035

Beta 2 and Hacking the DOM

So Beta 2 is live now. finally :) and life is good. I did have a few issues getting it running but thats what happens when you use daily builds between releases... I'm building this 'video showcase app' in silverlight for a here to be annouced group at MS and need to interact with all their old bits they build around flash... One of the issues is that they pass the data and a collection of objects and instead of passing the base JSONthey map the data and process it into this collection to pass into the 'showcase'. At first I went down the JSON road and since they wouldn't pass in the JSON or lest me call the service directly this turned out to be problematic. Using ScriptObject I could get to values and properties but how do you work with a collection in javascript from silverlight...

As intensely intuitive as it seems besides using GetProperty off of an instance of ScriptObject for properties I can also use it to grab collection items so that means something like this works:

(ScriptObject)SomeChild = (ScriptObject)foobar.getProperty("0");

basically I can pass in an indexer as if it was a property and actually get a reference to that element. Personally I have mixed feelings about this but it works. And I don't have to do script injection or some other weird ness to make it work.

Tuesday, June 3, 2008

Crossfader At TechEd

Aw My lifes work is imortalized for 5 minutes in Bill G's teched presentation.

check out the pictures at:

http://www.facebook.com/album.php?aid=38501&l=1b348&id=721326429


off the web:

http://www.microsoft.com/techedonline/default.aspx

Live Tech·Ed NA Developers Keynote delivered by Bill Gates Tuesday, June 3, 2008, 8:30–10:00am EST What better way to kick off this year’s first premier technical education conference, Microsoft Tech·Ed North America 2008 Developers, than with Bill Gates, Microsoft Chairman. Join us to hear and learn about the vision of the IT industry in the years to come. High Medium Low

Monday, June 2, 2008

More on Panels

I was playing around and made a few more panels. Lets start with a random panel. This panel builds on what we learned about the animating panel base and allows us to layout everything out randomly on screen. This is especially interesting for doing graphics randomly placed around the UI and is more for effect then what you would use in a real business application. A logical use for this might be a portfolio or other like function or just for fun. If we start with the Animating Wrap Panel we need to redo the arrange method starting with replacing the variables at the top with the following:

double Width = 0;
double Height = 0;
Random ThisNum = new Random();

Like the Wrap Panel we still need to run through all the panel children. Our loop should have its internal code replaced with the following:

Width = element.DesiredSize.Width;
Height = element.DesiredSize.Height;

double NewX = double.Parse(ThisNum.Next(
int.Parse(this.Width.ToString())).ToString());
double NewY = double.Parse(ThisNum.Next(
int.Parse(this.Height.ToString())).ToString());

if (MyFirstTime)
{
SetElementLocation(element, new
Rect(NewX, 1500, Width, Height), false);
}
else
{
SetElementLocation(element, new Rect(NewX, NewY, Width, Height));
}

In this case we see that we are creating new Random X,Y values so that our layout is unique every single time. We then like the other panels call the SetElementLocation in like manner. Other wise this panel is much the same as the others.

This panel allows us more interesting possibilities now we will address one more common panel that you might want to use and animate

Animating Radial Panel

So starting with the radial panel we need to do a little more math then the others. Building this panel we add 3 variables to the class itself like this listing:
protected void GetListOfPoints(int pointCount, double Width)
{
double x = Width / 2;

Radius = x;

double y = 0;

double theta = (2 * Math.PI) / pointCount;

for (int i = 0; i < pointCount; i++)
{
if (i > 0)
{
x = (Radius * (Math.Cos((i) * theta)));
y = (Radius * (Math.Sin((i) * theta)));
}

XList.Add(x + Radius);
YList.Add(y + Radius);
}
}

With out getting into great detail this method basically gives the points we need to layout our children on. Now we can alter the arrange override and we are good. In the arrange we start with variables like this:

double Width = 0;
double Height = 0;

GetListOfPoints(this.Children.Count, this.Width );
int Count = 0;

Width = element.DesiredSize.Width;
Height = element.DesiredSize.Height;

if (MyFirstTime)
{
SetElementLocation(element, new
Rect(XList[Count], 1500, Width, Height), false);
}
else
{
SetElementLocation(element, new
Rect(XList[Count], YList[Count], Width, Height));
}

Count++;The rest of the method is the same once we drop out of the loop like the wrap panel. In this case the biggest difference in the loop is having to track our position so we can get the right X/Y values for the layout.

By default like the other panels we did using the animating panel base we start be animating the children from off the screen below. All of these panels are included in the panel factory download off of HackingSilverlight.net. With that you can do all the hot panels you like.

http://www.hackingsilverlight.net/samples/PanelFactory.zip