How to add custom user control in same project in Lightswitch 2012?


  • Note: This is cross-posted from Stackoverflow for maximum coverage: How to add custom user control in same project in Lightswitch 2012?

    In the old version of Lightswitch (11) you could add a XAML user control to your Client project and reference the Telerik dlls as per these links:Extend Visual Studio LightSwitch with Telerik Dev Tools

    You would then change the built in grid to a Custom Control on choose the XAML user control by selecting the current Lightswitch project and this worked great.

    However, in 2012, this is no longer possible. It seems it works if your user control is in a separate project, but not if it is in the same project as before. The current project does not show up in the list and if you try to select it you get a message "You can only add project references to other Silverlight projects in the solution". Browsing to the Client .dll on disk causes VS2012 to crash.

    It's easiest illustrated with a video of the 2012 bug.

    How do I get this to work as before? I don't want to have to move the controls to a new project just because of a bug.

    thanks, Rodney - PokerDIY Tourney Manager - Web/Desktop/WP7 Blind Timer

    Friday, August 24, 2012 4:55 AM

All replies

  • Hi Rodney

    Kindly go through the below thread. Specially put more notice on Jewel's comment.

    Custom Control - Telerik Grid

    Hope this help...


    Rashmi Ranjan Panigrahi

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.
    This will help other users to find their answer quickly.

    Friday, August 24, 2012 5:17 AM
  • Hi Rodney,

    It's actually best practice to have your custom controls in separate project. This allows you to reuse it in another LS application, just by adding a reference to it. Otherwise you end up with multiple copies of essentially the same thing.

    Do you absolutely have to have it in the actual LS Client project?

    Hmm, just watched the video. The crashing part's not so good. It would depend on why it's crashing whether you'll be able to get around it if you must have the controls in the LS project. I strongly advise against it though, if my advise means anything to you. :-)

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
    By doing this you'll help people find answers faster.

    Friday, August 24, 2012 5:17 AM
  • Ok, I went through that thread - thanks - Jewel's comment was that it is not possible and has changed in 2012 as I have discovered too in the RTM 2012 version:

    "The reason I suggested a separate Silverlight project is that I have not seen how to get LightSwitch to show your custom control in the tree view when you click "Add Data Item"..."Custom Control".  In LightSwitch 2011,  I just added a silverlight user control to the UserCode folder of the Client subproject, did a build, and the new user control would show up in the list of custom controls from the LightSwitch screen designer.  But in Visual Studio 2012 RC and Visual Studio 11 Beta,  I haven't figured out how to get that to work.  So my workaround has been to add the user control to a separate Silverlight Library, then in the LightSwitch client project adding a reference to that library."

    @Yann: I appreciate that logic, however it does not really apply - each RadGridView control is highly customized to my business app and cannot even be reused across screens in the same app - e.g. the Projects list shows certain columns in a certain order with colour coding etc. on certain fields. It will never be reused (I can see how this argument is valid for simpler user controls like a Filter control or something, but not for the Telerik RadGridView).

    So it looks like there is no way around this? I wish VS2012 didn't crash each time I added a reference to the Client ;)

    thanks, Rodney - PokerDIY Tourney Manager - Web/Desktop/WP7 Blind Timer

    Friday, August 24, 2012 5:47 AM
  • Ok, so I moved all my controls into their own project and now the Win7 theme does not show up on load (when I view the control in the external project it is visible, but at runtime in the Lightswitch project it defaults to the black theme.

    Any suggestions?

    thanks, Rodney - PokerDIY Tourney Manager - Web/Desktop/WP7 Blind Timer

    Friday, September 07, 2012 6:48 AM
  • Ok, the solution to the Theme issue was to add the Telerik Win7 .dll to the core Lightswitch project (this is the only .dll I have in this project, the rest are only in my external silverlight project)

    thanks, Rodney - PokerDIY Tourney Manager - Web/Desktop/WP7 Blind Timer

    Sunday, September 09, 2012 10:46 PM
  • Just raised a question myself as this is related to a problem with the new project structure for Html clients -

    Lightswitch 2012, Silverlight Controls and HTML Client: Project structure changes

    Tuesday, November 20, 2012 3:08 PM