Tuesday, August 19, 2008

[C#, VS2008 ] One Solution, Mulitple Projects

So I was trying to create one solution which would act as a master build to build the multiple Silverlight projects we have on the go. I ran into slight issues when setting this up, so I thought I'd outline how I did it.

1. Create a "Blank Solution" project.
1a. File -> New Project
1b. Select "Blank Solution" from Other Project Types -> Visual Studio Solutions

2. Force VS2008 to always show the main solution.
This helps when adding existing projects, since for some reason the default in VS2008 is to make the first project you add to the solution the root... making it hard to add multiple projects. *
2a. Go to Tools -> Options [Show all settings] -> Projects and Solutions
2b. Check "Always show solution".

3. Add the desired projects.
3a. Right click the Solution in the solution explorer and Add -> Existing Project.
3b. Browse to select the csproj file from the desired project.
3c. Repeat a&b for all desired projects.

4. Setup any dependencies between the projects.
This step may not be needed if each project already has correct dependencies setup.
4a. Right click the Solution and go to "Project Dependencies"
4b. Select each project from the drop down and select any dependencies if they exist.

That should be it! Build your solution, and all the projects included in the solution should be built in the respective project folders.

* Thanks to Danny-T.co.uk


.

Thursday, August 7, 2008

[Silverlight] What is a .xap File?

So in my travels I bumped into a screencast, and in it, the presenter appended the .zip extension to the end of the .xap file and was able to open up a collection of files by unzipping it! I was like... woooooooah, that's something I didn't know.

What is an .xap file?
The .XAP file is a .zip compressed file that contains the client DLL for the Silverlight application as extra DLLs of assemblies that you are using in your application. This can be your own assemblies of user controls or assemblies that are not part of the Silverlight runtime by default that gets installed on the client.(2)
For more information regarding the files contained in the xap, most notably the AppManifest.xml file, please see the following blogs:
(1)http://pietschsoft.com/post/2008/03/Silverlight-Anatomy-of-an-XAP-file.aspx
(2)http://blogs.msdn.com/katriend/archive/2008/03/16/silverlight-2-structure-of-the-new-xap-file-silverlight-packaged-application.aspx


.

Friday, July 25, 2008

[Silverlight] Adding an image - Why isn't the image showing???

At first all the examples seemed so simple, however, my image was still not showing up when I ran my application.

As it turns out I was placing my image in the incorrect location. I have a Silverlight web application, and as it turns out:
The paths are relative to the .xap file found under the folder [myAppName]/[myAppName]/[myAppNameWeb]/ClientBin.
Like a noob I had been placing them in the folder that contained the .xaml/.cs pages and didn't understand why the images weren't showing...doh!


.

Monday, July 21, 2008

[Silverlight, C#] Animations on Transforms...

So I have been creating a little user control which allows me to dynamically create animations from 'templates', hook them up to elements, run the animation and then kill the animation once it is complete.

I have created a fadeIn/FadeOut quite successfully, however, when trying to animate a shrink/grow I have ran into an issue.

I cannot seem to create an transform animation on an element that does not explicitly have a Group Transform [Scale X / Y in my case] setup on it.

With other properties, like Opacity, you can still animate the property even if it has not been explicitly setup... but this does not seem to be the case with transform properties. I will be doing some forum searching on this tomorrow.


.

Tuesday, July 15, 2008

[Silverlight, C#] WebClient Caching Issue

In my project I am let the user do dynamic loads and saves to the server. During this process I found out that given identical URLS, WebClient [and HTTPBrowserRequest] will retrieve cached copies of the retrieved files. As handy as this is, I couldn't find a way to flag these classes to NOT cache.

Thus, thanks to this forum post, I have created a workaround which involves creating a unique URI.
client.DownloadStringAsync(new Uri(Global.PhpURL + "Graphics/" + fileName + "?FudgeCache=" + DateTime.Now.ToString()));
Fun Stuff. Maybe it will get fixed later, since from what I've read you can flag no cache in WPF.

.

Friday, July 11, 2008

[Silverlight, C#] TextBox Fuuuuuuuuun!

So this afternoon I dove into the wonderful world of TextBoxes, as I now wanted to add the ability for people to add text to my WYSIWYG drag/drop app. And boy oh boy does this look fun [*rollseyes*]. Tabstops and focus issues oh my!

Giving Focus to a TextBox Programatically

While I thought this was as easy as calling the Focus() function, but as it turns out, you also have to make sure that the IsTabStop property is true as well.
this.mytextbox.IsTabStop = true;
this.mytextbox.Focus();

Focus Puts the Caret in the TextBox, but Keystrokes are not captured
/shrug

[Silverlight, C#] Determining Coords with respect to the application

So I am working with multiple user controls, and I have elements in those user controls that I want to drag/drop them seamlessly between without the user knowing about the fact that the elements were being passed back and forth between user controls.

Originally I had been recursively adding together the Top/Left values all the way up to the "root"... however, when I introduced the user controls, it became tricky. Each user control has it's own "root"... so my recursive function would stop at the user control root, and thus my Top/Left values were now only relative to the user control root! Doh!

After digging for awhile, I came across a wonderfully handy little function:
UIElement.TransformToVisual
Returns a transform object that can be used to transform coordinates from the UIElement to the specified object.

With this I made a function that would return me a Point containing the offset X/Y values that would give me the relative coord change needed to move to the new coord space of the wrt element.
/// < summary >
/// Returns the Point that can translate the desired element w.r.t to another element.
/// < /summary >
public static Point getVisualCoordsWRT(UIElement findMe, UIElement wrtMe)
{
  GeneralTransform gt = findMe.TransformToVisual(wrtMe);
  return gt.Transform(new Point(0,0));
}

So to get coords wrt the application I could do this:
Point offset = getVisualCoordsWRT(controlElement, Application.Current.RootVisual);


Thanks to this Silverlight forum post.

.