Ioan Lazarciuc's Weblog I program, therefore I exist.

9Apr/1051

Update for Silverlight Sidebar Gadget Project Template

For the past few weeks I’ve been working on fixing a number of bugs signalled about the Silverlight Gadget Template I created a while ago. I’ve had to work around some strange issues and try everything I could to make the gadget development experience as pleasant as possible. I’d like to thank Kiran Bachu for his valuable support in finding bugs and testing the gadget template.

Version 1.8 of the gadget is released for the following Visual Studio/Silverlight version combinations:

 

  Silverlight 3.0 RTW Silverlight 4.0 RTW or Newer
Visual Studio 2008 Ver. 1.0 available here N/A (not supported)
Visual Studio 2010 Available for C# and VB Available for C# and VB

I modified the CSS for the HTML page that hosts the flyout and the gadget itself in order to eliminate all margins and padding. You can set these from the Silverlight controls.

I fixed the issue with docking/undocking the gadget. Aside from a JS bug I had, there was also some weird Silverlight behaviour that cause the freeze on some machines.

I exposed the SettingsClosed event for both the docked and undocked Silverlight controls and fixed an issue related to saving settings values.

I added build events for the SilverlightGadgetWeb project that create a .gadget file that can be used to install/update the gadget. I also added code to actually install/update the gadget on each build. I did this in order to provide an easy way of trying out code changes.

I tried to fix the Silverlight application references in the SilverlightGadgetWeb project, but the only way that can be achieved is by providing a custom wizard for the project template that requires installation in the GAC. For now I think this requirement would be too strong for the template installation process. Aside from re-adding the Silverlight project references I also recommend setting the project dependencies manually to make sure that the project is the last one to be built in the solution. You can do this by right clicking the web project, choosing “Project Dependencies…” and then selecting all the Silverlight projects. (see below for details)

I also tried to arrange for “F5 debugging” in Visual Studio, but it was not possible. I managed to set the sidebar as the start program for the web project, but the debugger failed to attach to the process if the Silverlight gadget was running. Even if attaching succeeds at start-up (when no Silverlight gadget runs), when I added a Silverlight gadget the debugger crashed. In conclusion, Debug->Attach to Process is still the best way to debug gadgets.

I will be adding more versions of the template as soon as I get around to it, so stay tuned if your development configuration is not available yet.

UPDATE: In version 1.5 of the template I created a project template wizard to properly create Silverlight application references for the SilverlightGadgetWeb project and to establish a correct build order. This wizard also prompts for the Silverlight version to use when creating the projects.

UPDATE: In version 1.6 of the template I fixed the F5 debugging scenario by providing a fake SilverlightGadgetDebugger project in the template that runs a custom app which attaches the Visual Studio instance to the Sidebar process (more info on the workaround here). Starting with this version, I’m also providing a Visual Basic.NET flavour of the template. For the download link, check the table above.

UPDATE: Version 1.7 of the template offers a fully automated debug experience within Visual Studio 2010 for the gadgets. In short, the SilverlightGadgetDebugger  project will close any running version of the Sidebar and start a new one containing only the gadget to be debugged. When debugging/running is done, the original Sidebar (if it was running) is restored. Also, a bug involving detection of the 32 bit Program Files folder (which was used to detect installed Silverlight versions and locate the 32 bit Sidebar) has been fixed.

UPDATE: Version 1.8 of the template offers support for debugging 64 bit gadgets. This can be done by setting the Target Platform to “x64” for the SilverlightGadgetDebugger. Changes to the Target Platform require a reload of the SilverlightGadgetDebugger project, because Visual Studio does not update the values of the parameters used in command line parameters for debugging.

Comments (51) Trackbacks (0)
  1. Any idea when you’ll have the template update for 4.0 now that it’s been released?

  2. Just as soon as I can see some Silverlight 4.0 RTW tools for Visual Studio 2010 RTM available on http://www.silverlight.net/getstarted.

  3. The Silverlight 4.0 RTW version of the project template is now available on the Visual Studio Gallery (check the link in the table above).

  4. I downloaded, built, and ran the new VS 2010 Silverlight 4.0 version but the gadget doesn’t display right and keeps prompting me to download Silverlight but then during installation aborts because it is the same version as is installed already. Any help appreciated.

    -Scott

  5. You probably have a 64 bit version of Windows. Kill the sidebar.exe process from the task manager, then run the 32 bit of it from %programfiles(x86)%\Windows Sidebar\sidebar.exe. After this the gadget should work.

  6. That was exactly it – thank you very much for your help and the template as well.

  7. Any change you could get this to work on the visual studio express editions. When I double click I get ‘This extension is not installable on anyh currently installed products. I have VS express c# and VS web developer express, both 2010

  8. Hi, what do you think about this issue with 64 bit versions of Windows?

  9. David, I’ve upgraded the template to install on Visual Web Developer Express 2010 as well. You can use the same link as in the post above.
    Iván, the issue with the 64 bit Windows is that Silverlight cannot run in a 64 bit runtime. To work around it you just have to start the 32 bit of sidebar.exe. If in future versions of Silverlight 64 bit support will be added, this will no longer be necessary.

  10. Hi,

    From the sample, if I set border to a transparent background color the content become pink. It’s a well known issue.

    Do you have input on how to fix this ?

    Thanks 🙂

  11. I’ve given this some thought, and here’s the bad news:
    The Windows gadgets use the Internet Explorer engine for rendering. This means that the only way to obtain transparency (in IE8) is to use PNG images with the alpha channel set to 0 (there is a CSS setting I found on the web -ms-filter: “progid:DXImageTransform.Microsoft.Alpha(Opacity=0)”; but it does not work in gadgets for me).
    As you’ve pointed out, having the Silverlight control use a transparent background causes magenta pixels to pop up uncontrollably (due to the transparent PNG).
    The bottom line is that with the current setup (IE8 + buggy PNG transparency in gadgets) there is no way to use a fully transparent background in the Silverlight gadgets. However, you can use transparency to define “oddly” shaped gadgets (circle, rounded rectangle, etc). You just have to place your text & other content in opaque areas.
    Things might change once IE9 is out, but we’ll have to wait and see.
    I am tracking this issue and as soon as I find it fixed, or a proper workaround becomes available, I’ll release a new version of the template to incorporate the fix.

  12. Hi,

    First off gratz on the template! has helped me a lot.

    I am however having an issue with the flyout, it shows up when i click on it, but will not disappear(go back to docked state). The only way i am able to get it to go away is by clicking away from the gadget, then it returns to the docked page.

    I tried putting a button with SilverlightGadget.Flyout(false); in the click event but then it just flashes as it goes to docked state and then back to the flyout.

    Any help would be appreciated.

    Thanks

  13. I’m doing some guesswork here, but it seems that as long as the flyout HTML page is active (including click events for buttons on that page), it will keep the flyout in view.
    My guesswork seems to be confirmed by an experiment I tried: call HtmlPage.Window.Eval(“setTimeout(‘System.Gadget.Flyout.show = false’, 1000);”); from the event handler, and the flyout page will disappear after the indicated time interval (1 second in my case). This is because the code that hides the flyout does not originate from the flyout, but from a different place in the JavaScript runtime(setTimeout).
    This would be a workaround for not being able to close the flyout from flyout page itself.
    Please let me know if this solves your issue.

  14. Thank you!

    Nice little workaround. Solved my problem.

    One other thing i am trying to do, is to get the undocked state to show from clicking a button on the UI from the docked page.(I Need to work on my Jscript)

  15. There’s no way to do that. The JavaScript API only allows to read the current docked state of the gadget.

  16. The joke’s on me… Apparently I had a bug in the SilverlightGadget.Flyout(bool) class. It always called flyout(true), regardless of the input parameter. I’ll be releasing an update for the template soon. If you don’t want to use the setTimeout workaround, you can change the code for SilverlightGadget.Flyout(bool) to be:
    var value = show ? “true” : “false”;
    HtmlPage.Window.Eval(String.Format(“System.Gadget.Flyout.show = {0};”, value));

    Sorry for the inconvenience.

  17. I am a bit confused on calling a WCF service from the gadget. Can you provide more information on how this is done.

    Note: I can see in my browser that a call is waiting on the server that is hosting the WCF service but the gadget doesn’t seem to return the result.

    Thanks.

  18. Where is the WCF service hosted? If it’s on another machine (and in the case of Sidebar gadgets I would assume the answer is yes), then you need to define cross-domain access rules. You can find more information here.
    If this does not solve your issue I will need to know more about your service (configuration, where you deploy it) and how you access it from Silverlight.

  19. Hi,
    How i can run gadget out of browser? I need use AutomationFactory, but when I use CreateObject I get error (Required elevated trust when running in OOB checked)
    Thanks

  20. Hi,
    I don’t understand what you’re trying to do. What do you mean by “run gadget out of browser”? Windows gadgets run in the sidebar.exe process.

  21. Yes, I understand that gadgets run in the sidebar.exe process 🙂
    My gadget need use AutomationFactory. For use AutomationFactory in silverlight, project must “Enable running application out of browser” and “Required elevated trust when running outside of browser”, but when I use AutomationFactory.CreateObject I get error.
    Gadgets can use AutomationFactory and COM?
    I hope you understand me now 🙂

  22. Great job! Your extension really helps set the stage for doing cool stuff with gadgets. I’m thinking of creating some code “dashboard” kind of stuff for a business. Thanks again!

  23. ak1ra, I think I understand your problem now. You cannot detach Silverlight apps running in a Windows Gadget because the gadget framework is strongly tied to using a web browser (the only officially supported way of writing gadgets is with HTML + JavaScript).
    The good news is that you can interop with COM using ActiveX and/or JavaScript and use the web browser integration features from Silverlight to relay information between the Silverlight controls and the COM handling JavaScript. I have not had to do this before, so I can’t help you with COM interop in gadgets, but I know that several of the gadgets out there use it. You can go to the Gadget gallery, install such a gadget (for example a CPU/GPU meter gadget) and then look through its JavaScript (gadgets are installed in your user dir under AppData\Local\Microsoft\Windows Sidebar\Gadgets) to check how they do interop.

  24. Thanks for the great template! It works perfectly fine for me. However, there is a strange behavior when switching from “undocked” to “docked” state. The Silverlight app which is shown in the “undocked” state is being destructed every time I switch to “docked” mode even though the utils.js only hides the silverlight app. I wonder if this is a restriction of the Gadget API or if there is a solution/workarround for this problem.

    To reproduce this problem just open the template and add a simple button control to the “undocked” view. Now, run the gadget, switch to undocked mode, press the button, and switch back to docked mode. If you now switch to undocked mode again it will construct a completely new instance of the undocked view. Any thought / ideas on this issue? The only workarround I see at the moment is making the app persistent and synchronize the “docked”, “undocked” view utilizing the GadgetSettings class.
    BTW: If you don’t press anything on the “undocked” view no new instance will be created.

  25. i was unable to start debugging, after F5 a message box appears:

    —————————
    Could not attach to Windows Sidebar
    —————————
    The sidebar.exe process was not found.
    —————————

    I’m using Visual studio 2010, on windows 7 64bit

  26. Antonio, I’m going to need more information about the circumstances of the error.
    Do you always get this error?
    Does the file %programfiles(x86)%\Windows Sidebar\sidebar.exe exist on your machine?
    If the file exists, what happens when you run it? How many gadgets do you have active?
    When you check the process list in the task manager, how does the running sidebar.exe process appear? (sidebar.exe, sidebar*32.exe)
    What happens if you try to debug the gadget while the %programfiles(x86)%\Windows Sidebar\sidebar.exe process is running?
    What happens if you just try to run the gadget (Ctrl+F5) while the process is running/stopped?

  27. Yes,
    the sidebar.exe exists, and it works (I’m using for example Daemon Tools gadget).
    In task manager the running process is sidebar*32.exe.
    If I close the 32-bit process, and launch the 64 bit sidebar,
    when I start debugging, the same messagebox error appears, and in task manager I see that the 32-bit process is started.

    Running gadget without debugging, the window with Stop button and a Running Sidebar Sandbox message appears. And also a command prompt window starts.

    If a start without debugging when no sidebar.exe process is executing, the 32 bit sidebar is started.

    The problem seems to be that Visual Studio can’t attach the process

  28. Hello MASTER,

    Absolut thanks for the brilliant work. I hate it to work with the JScript Stuff… and U rescue from this hell… 🙂

    But i have not so many experience with Silverlight and can find a Solution how i can Close the Settings Page if the User Clicks a (Save) – Button. Can u help me??

  29. Howard, the settings page always comes with an Ok and Cancel buttons for saving/discarding settings. If you check the Page.xaml.cs file in the SilverlightGadgetSettings project, you will find an event handler ev_Closing that has the logic to determine whether the settings are supposed to be saved or discarded. You can place your own save logic there.

  30. Antonio, can you manually attach (Debug->Attach to Process) Visual Studio to an instance of the sidebare where your gadget is running?

  31. Yes, actually I have to attach manually to debug

  32. Hi All,

    Super project! Read all info and comments now. Se some familiar stuff. Like error of side bar from antonio. i get it sometimes. I’ll start the sidebar again and all is ok. I guess it’s a sidebar crash… also the clipping of the settings page. May-bee it’s still the case in the VB template only?

    @Anyone interested: Im have developed, with tis template, a Silverlight gadget with a local WCF service (Exe in tray). The exe application in the system tray is connecting to SQL Server/Oracle and is providing services which are consumed by the gadget. So, it’s a way to have control over the local computer since the gadgets can’t because of the Silverlight running in the sandbox.

    Also the application is detecting 64 bit sidebars and replacing them with 32 bit.

    Interested: leave a message on the website! (www.proovit.com)

  33. Another Question to the MASTER 🙂

    i didn’t need the “SilverlightGadgetUnDocked” how can i dissable this page and also the little Arrow on the right side of the Gadget if you hover with the Mouse…

    THX

  34. Hey nice. The new fixes were good.

  35. Okay 4 all of u: if you didn’t need the “SilverlightGadgetUnDocked” – Page u have to comment the line “System.Gadget.onUndock = undockGadget;” in \SilverlightGadgetWeb\script\utils.js

    It Works…
    Howard

  36. Awesome template, love it. Got a cool clock up and running in minutes, one problem though, when I install on Window 7 64bit with Silverlight 4.0.60129 I get the please install silverlight. So my gadget works in the debugger it just wont install to run on its own. Is there something I am doing wrong?

  37. I figured out the issue, I am running 64bit windows and Silverlight does not support 64bit, so my gadget wont work! Sorry for the noise.

  38. Is there a cross-domain issue with trying to pull in images from a URL? I am using the Sharepoint API’s to successfully pull in an image link from a list, I format that link into a Bitmap using the URI as the source but no matter how I configure things the image never is shown. I have also just started with the plain vanilla template, added an image and hard coded a link to a picture from the web. No luck…is there really no way to access images via URL?

  39. Pulling any kind of resources from cross host URLs is an issue in Silverlight. You either need cross host access for your SL app (which not all sites provide), or you need to find a workaround. You can find info on this at http://msdn.microsoft.com/en-us/library/cc189008(v=VS.95).aspx and http://www.eggheadcafe.com/tutorials/aspnet/c0046ba1-5df5-486a-8145-6b76a40ea43d/silverlight-handling-crossdomain-images-and-gifs.aspx
    It depends on your scenario, but you should try to get the images in your gadget package if possible.
    If not, the worst case scenario will require you to interop with JavaScript to display the image as HTML on top of the SL control.

  40. Hey, I’ve started messing about with the template this week, I can’t seem to make a call to any functions when I use the template, is there an example template floating somewhere that done “Something” that I could base my own gadgets on the?

    Cheers

    Scott

  41. What do you mean by “I can’t seem to make a call to any functions when I use the template”? Are you getting an exception? Have you tried debugging the code?

  42. Hi!
    How to work with WCF services?
    I’ve created WCF service in SilverlightGadgetWeb and add reference to this service to SilverlightGadgetDocket.
    But when I try to create client object (for examp WCF service – service1 and client – service1client) I’ve got KeyNotFoundException on this line.
    if (e.Action == CloseAction.Commit)
    {
    service1client obj = new service1client();<-keynotfoundexc
    What's is wrong?

  43. You cannot create the WCF service in the same project(s) as the Silverlight gadget. You cannot host a service in the sidebar. You will have to host the service somewhere else and then make sure you have granted access to Silverlight apps at the location where you host the service.

  44. So I need:
    1)to create new project WCF service
    2)and then in gadget project in docked(for example)->add service reference->http://localhost:8732/Design_Time_Addresses/GetWeatherXmlService/Service1/
    ?
    GetWeatherXmlService – WCF service(however it doesn’t create svc file).

  45. oh. sorry. I mean add reference to http:://localhost:8743/Service1.svc

  46. I’ve got a question about debugging.

    I put a breakpoint somewhere on Page.xaml.cs. But when I start project – nothing happens. It’s ended with Debuggin Sidebar Sandbox and gadget is not shown. When I delete breakpoint – it works normal. So…How to test my own method or classes in the project?

  47. Where did you put the breakpoint? In the load event handler? Also, if you debug Silverlight code, then make sure script debugging si disabled for both internet explorer and Other (in IE options).

  48. I solved problem like this – I start application and then clos it. Then attach proccess to browser. And then start again.
    Sometimes it doesn’t work so I restart program.

    How to work with different HttpWebRequest or WebClient classes?I mean for example for SilverlightGadgetSettings
    in constructor Page I initialize WebClient object
    client = new WebClient();
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);

    And then when I close settings
    if (e.Action == CloseAction.Commit)
    {
    //осуществить перезагрузку погоды
    client.DownloadStringAsync(new Uri(uri+”Polotsk”+”&hl=en&oe=UTF-8″,UriKind.RelativeOrAbsolute));
    }
    I call asynchronous method.
    private void client_DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs b)
    {
    if (b.Error == null)
    {
    s = b.Result.ToString();
    }
    else MessageBox.Show(“Error!”);
    }
    But nothing happens. Debugger never enter method.
    Does sth wrong with method?Or I need to put handler and webclient declaration in another project?

  49. Hi, Is there any chance of recreating this to work in VS2012? Or can you point me in the right direction to do so?

  50. I’ve updated the template and published the update to the Visual Studio Gallery. It should work on VS 2012 now as well.


Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

No trackbacks yet.