views:

149

answers:

1

Microsoft has a handy reference of the various controls in the System.Windows.Controls namespace and which controls are included in the runtime.

For any controls listed here that aren't included in the runtime, you have to include the reference to the System.Windows.Controls assembly and select "copy local" in Visual Studio. So that's what I'm currently doing and it works.

However, by including this DLL I'm adding almost 80 KB to my XAP file (and my XAP file is only 110 KB). The only control I'm using that requires it is the GridSplitter. Is there a way to rebuild a condensed version of this assembly that includes the GridSplitter only?

+2  A: 

It looks like I just found the answer for Silverlight 2...

Source Code for Silverlight 2 Runtime and SDK Controls

And I think that'll work for me for now. I should be able to go through the project and exclude all the unnecessary bits from the project and do a rebuild.

I'm still using Silverlight 2 but I will be switching to 3 in a couple months. And I can't seem to find the same thing for Silverlight 3. Maybe the source is not available yet for Silverlight 3?

UPDATE:

So I got this working after jumping through some hoops. At first I downloaded the source project from Microsoft and then just started removing stuff. But then I noticed that I couldn't build the solution. In fact I couldn't build an unmodified version of the solution either. I was getting errors about strong name verification. I tried unchecking strong name signing from the "Signing" section of the project properties but I got the same error. I even added the assembly to the strong name verification skip list and finally got past the error. But when I tried to include the new assembly in my Silverlight project and run it in a browser, I'd get a blank screen (the Silverlight control never loaded). I'm still not sure why but I'm sure I was missing something.

Finally I just created a fresh project. It seems I should've done this from the beginning. I just needed to create an empty C# Silverlight Class Library for the GridSplitter. Then I started adding the source files necessary for the GridSplitter to this project and then I set the namespace and assembly name to System.Windows.Controls. After building this project, and referencing it in my Silverlight app it finally worked. The result: a 60 KB savings.

I wrote a little more about this here:

http://regexhero.net/blog/2009/09/optimizing-silverlight-xap-file.html

Steve Wortham
The Silverlight 2 code should work in Silverlight 3.
KeithMahoney
Yeah, good point. I think this is the first time I've accepted my answer to my own question.
Steve Wortham