Answered How to specify entities as Control.SupportedDataTypes?

  • Wednesday, November 10, 2010 12:57 PM
     
     

    Hello,

    I have a Silverlight control (a textbox that provides suggestions as you type) I want to use in LightSwitch as well. I created an extension as shown in the training kit. What do I need to specify in the <Control.SupportedDataTypes> section if I want to use the control for the selection of entities? For example I might have a screen for orders where the according customer can be selected by the control (it has ItemsSource and SelectedItem properties).

    Regards,

    Daniel

All Replies

  • Thursday, November 11, 2010 6:39 PM
    Moderator
     
      Has Code

    Hi Daniel,

    SupportedDataType is a subset of the entity. In fact, what the <control.Supportdatatypes> means is what kind of data is accepted by the particular control - string, int16, int32, etc.

    To get access to a particular entity in your control code, you need to access to ContentItem.

    I would recommend something like the following code to get a data context:

     IContentItem dc = (IContentItem)this.DataContext;
    

    Of course do some checking to see if dc is not null. Then, if you then do a dc.childitems you then see the collection of the entity as well as values set at each field.

    From there you can use IEnumerable on the ContentItem to query via linq to get the necessary values that you are after.

    The key think here is if you look at the architecture presentations on LightSwitch is that the application architecture uses the V-VM-M (View-ViewModel-Model) approach. With that a control (View) cannot go directly to the data (Model). The way that you can see both sides is via the ContentItem (ViewModel). If you debug it, you will see both sides of the application architecture come together.

    I hope this helps.

    Cheers,

    Campbell


    Program Manager - Microsoft Visual Studio LightSwitch - Extensibility
  • Thursday, November 11, 2010 7:27 PM
     
     

    Hi Campbell,

    thanks for the answer. I'm not sure if it really helps though. ;)

    When I write int32 in the SupportedDataTypes section, then I can use my control for integer properties. By default LightSwitch uses a TextBox for these, but I can select my control instead in the screen designer.

    I want to be able to use my control for entity-type properties as well, so that I can use it to pick the customer on my orders screen for example (instead of the modal window used by default for selecting related entities). What do I need to do to make my control show up there as well?

    Regards,

    Daniel

  • Friday, November 12, 2010 7:31 AM
    Moderator
     
     

    Hi Daniel,

    Okay, I a trying to understand what you are asking here. Are wanting to select a datatype in the entity designer screen, or are you asking for a control in the screen designer that allows you to set a control to collection (in this case a enty), similar to what the datagrid control does?

    Thanks,

    Campbell


    Program Manager - Microsoft Visual Studio LightSwitch - Extensibility
  • Tuesday, November 16, 2010 9:37 AM
     
     

    Sorry I didn't make this clear.

    In my model I have a one-to-many relationship. Every customer can have multiple orders. So when I create a new order, I need a way to select the associated customer. The default option LightSwitch offers here is a modal dialog, but i could also use a drop down list for example.

    What I want to do is use my own control for selecting the customer. Just like a ComboBox, it has an ItemsSource property and a SelectedItem property. My problem is that I can't select my control in the screen designer for the customer property of my order entity. It doesn't show up.

    My guess was that this happens because the datatype (Customer) isn't registered in the SupportedDataTypes section of the lsml-file. When I put Int32 in there for testing purposes, my control shows up in the screen designer as an option for representing int properties. But maybe I didn't get something here and therefore my question wasn't clear.

    What do I need to do to tell LightSwitch to use my control for selecting the customer (by binding the CustomerCollection to its ItemsSource property and the Customer to the SelectedItem property)?

  • Wednesday, December 01, 2010 6:14 PM
    Moderator
     
     Answered

    Hi Skleni,

    Sorry for the delay. After reading your email a few times and doing some investigation with the team. I think what you are after is the following:

               IsPicker="True"
               SupportedContentItemKind="Details"

     

    A details node is for controls that bind to an entity and what you are descibing here is a picker like control. The SupportedDataTypes is not relevant here.

    Thanks,

    Campbell Gunn  


    Program Manager - Microsoft Visual Studio LightSwitch - Extensibility
  • Friday, December 03, 2010 7:17 PM
     
     
    Thank you. :)
  • Tuesday, February 01, 2011 8:22 PM
     
     
    You may also want to check out a post I put up about defaulting to particular controls for datatypes.  Check this out.
    Derek
  • Wednesday, February 02, 2011 1:17 PM
     
     

    Skleni,

    You sound like you are going down a road I have travelled.  Please check this post out for another interesting tidbit.


    Derek