Tuesday, September 23, 2008

[Silverlight, C#] Polyline - Adding Points Does not Seem to Update on UI

I have been working on a small little drawing editor, which would allow the user to draw lines by clicking and dragging. I was using a Polyline to do this, and with every mouse move [or in some cases clicks] I would add a new point to the Polyline Points collection.

This, however, did not seem to work for me. When I added a new point directly into the Points collection, I saw no change in the actual UI indicating that the point had been added.
Polyline myLine = new Polyline();
// Setup visual look of polyline.
myLine.Points.Add(e.getPosition(null));
Not until I removed the element and then re-added it to the parent again could I actually see the new point.

I didn't want to have to remove and re-add to the DOM each time, but I found that I could force the UI to update if I actually changed and then reassigned the PointCollection of the Polyline.
PointCollection ptColl = myLine.Points;
ptColl.Add(e.getPosition(null));
myLine.SetValue(Polyline.PointsProperty, ptColl);
Something about this just doesn't seem right, but maybe I am misunderstanding something key. I am uncertain if this is a bug in beta 2, however, this was my work around for the issue.


.

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