Beth's Chinese blog
I’ve been trying to stay on top of the forming LightSwitch community and have been collecting a list of bloggers and community resources that talk about LightSwitch. It’s exciting to see people so enthusiastic about the product. I’m sure I haven’t spotted them all but here are some notable bloggers & emerging communities about LightSwitch. If you know of more links please post a comment to the end of this post! As the ecosystem builds up, I’ll create a “Community” page for the LightSwitch Developer Center.
Microsoft Blogs & Bloggers:
Microsoft Sites and Forums:
Community Blogs & Bloggers:
Community Sites and Forums:
Enjoy! (and Happy Holidays!!!)
To make it easy for developers to make sure they’re getting all the latest technical information around developing SharePoint solutions, the SharePoint, Visual Studio and Office User Assistance teams have decided to combine their blogging efforts into the SharePoint Developer Team Blog. Think of it as your one-stop shop for developer-centric SharePoint information, straight from the product teams and user assistance folk responsible for SharePoint Foundation, Server, SharePoint Online, and the SharePoint development tools in Visual Studio.
Here’s what you can expect from this blog going forward:
So we’re hoping you’ll subscribe, and pass the following easy-to-remember URL on to your SharePoint developer friends and colleagues:
http://blogs.msdn.com/sharepointdev/
And if there are particular things you’d like to see covered or discussed, by all means leave them a comment.
Enjoy!
Note: This article has been updated for Beta 2 on 3/17/2011
Summary Properties in LightSwitch are properties on your entities (tables) that “describe” them (kind of like the .ToString() method on objects in .NET). A summary property is used by LightSwitch to determine what to display when a row of data is represented on a screen. Therefore, it’s important to get them right so that your data is represented to users in a clear way. In this post I’ll explain how to specify these properties on entities as well as how they work in LightSwitch applications.
Regardless of whether you are creating new database tables or attaching to an existing data source, summary properties are used to describe your entities as you model them in the designer. By default, LightSwitch will choose the first string property on your entity as the summary property. For instance, say we have a Customer entity with the following properties pictured below. If you select the Customer entity itself (by clicking on the name of it) you will see that the summary property is automatically set to LastName in the properties window. This is because the LastName property is the first property listed as type string.
In most cases this is the correct behavior you will want, however, for a Customer it makes more sense to display their full name instead. We can easily do this using a computed property. To add one, click on the “Computed Property” button at the top of the designer. This sets the Is Computed property in the properties window for you. Name the property FullName and then click on the “Edit Method” link in the properties window. This method is where you return the value of the computed field.
Computed fields are not stored in the underlying database, they are computed on the entity and only live in the data model. For FullName, I will return “LastName, FirstName” by writing the following code (in bold).
Public Class Customer Private Sub FullName_Compute(ByRef result As String) ' Set result to the desired field value result = Me.LastName + ", " + Me.FirstName End Sub End Class
To set the FullName as the summary property, go back and select the entity’s name and you will now see FullName in the dropdown on the properties window as an available choice to use as the entity’s summary property.
Summary properties are displayed anytime you use the Summary control on a screen or when LightSwitch generates a layout for you that needs to display a description of the entity. For instance, to see this summary property in action create a search screen for the customer. Click on the “Screen…” button at the top of the designer, select the Search Screen template and select Customer as the screen data:
(Note, if you don’t have any records in your development database then also add a New Data Screen to enter some data first).Take a look at the Full Name label control in the screen designer of the search screen. Because this is a summary property it will display as a hyperlink to allow the user to open the specific record as indicated by the “Show as Link” in the Appearance section of the properties window. You can also choose which screen it should open. By default, the default edit screen is opened.
Hit F5 to run the application and open the customer search screen. Notice that the Full Name field is displaying as a clickable hyperlink.
If we click it, then then LightSwitch will generate an edit screen for us to access the record. Notice that the titleof the generated Edit screen also displays the summary property:
Summary properties also show up in child grids and modal window pickers as well.
Summary properties are not required to be strings, they just have to be able to be represented as strings. For instance, maybe you have an entity that captures date ranges or some item that would be better represented as a date. For our example say we have an Appointment entity and we’ve set a relation where a Customer can have many Appointments. The Appointment table has properties Subject, StartTime, EndTime and some Notes. We can select any of these properties as summary fields. You can even mix+match them by creating a computed property just like before, you just need to make sure the properties can be converted to a string.
Private Sub Summary_Compute(ByRef result As String) ' Set result to the desired field value result = Me.StartTime + ": " + Me.Subject End Sub
Another thing that you can do is show data from a related entity. For instance if you have an OrderDetail line item that has a reference lookup value to a Product table, you may want to display the Product Name on the OrderDetail. Create a computed property and then just walk the association to get the property you want on the related entity. Just make sure you perform a null check on the related property first:
Private Sub Summary_Compute(ByRef result As String) ' Set result to the desired field value If Me.Product Is Nothing Then result = "<New Product> - Quantity: " + Me.Quantity Else result = Me.Product.Name + " - Quantity: " + Me.Quantity End If End Sub
Keep in mind that summary properties are meant to be displayed throughout the application and should not be too lengthy or complicated. Keeping them down to 50 characters or less will make the application look less cluttered.
This Wednesday December 8th at EastBay.NET UG in Livermore I’ll be on a panel of Microsoft experts and MVPs that will be there to answer your architecture and development questions. We’ll also be hosting a really fun 30 minute FUNdamentals session with Remi Caron (MVP from the Netherlands) who will be talking about his latest “Cows in the Cloud” project. Check out the details below and register for this event!
.NET Developers Open Forum & “Cows in the Cloud”
When: Wednesday, 12/8/2010 at 6:45 PM, FUNdamentals starts at 6:00PM Where: University of Phoenix Learning Center in Livermore, 2481 Constitution Drive, Room 105
This session will be a panel discussion hosted by Microsoft experts and MVPs: Remi Caron (MVP), Beth Massi (that’s me :-)), Robin Shahan (MVP), Peter Tweed, and Adwait Ullal. What do you think about developing for the cloud? How are you dealing with learning WPF, Silverlight, and so many other new technologies? Questions about Windows Phone or SharePoint development? Has your team gone Agile? What went right/wrong with your development projects in 2010? What can we look forward to in 2011? Come participate in the discussion and enjoy the pizza and soda (provided by Slalom Consulting).
Before the main panel discussion we’ll also be having a short 30 minute talk for our FUNdamentals session with Remi Caron on his latest “Cows in the Cloud” project. This session starts at 6:00PM. Remi will be talking about a project that covers one of the oldest trades we as humans have (farming cattle) and the ‘latest’ technology hype, cloud computing. He will discuss this Azure-based cloud application to track dairy cows in the Netherlands and the basic concepts behind the technology. He’ll address some of the technical challenges but also customer adoption issues and legislation. Ever thought about cow privacy? Well you probably will after this talk.
Click here to register for this event!
Hope to see you there!
NOTE: This information applies to LightSwitch Beta 1 ONLY. For V1 release (RTM) please see Adding Static Images and Text on a LightSwitch Screen
We’ve had a couple questions on how you can add your own static images and logos to your LightSwitch applications so I thought I’d detail a few ways that you can do this to make your applications look a little more branded without having to load a completely different shell or theme. When you have an image property on your entity, LightSwitch handles creating a nice image editor for you to load and save images in your database. However sometimes you just want to add a static image or logo to your screens that aren’t part of your data entities. There are a few ways you can do this.
The first method just displays an image onto the background of the application itself. You can see it when the application loads and also when all screens are closed. To add the logo to your application, go to Project –> Properties and select the General tab. There you can specify the Logo Image.
When you run your application the logo appears on the background of the main window area.
There are a couple ways you can add a static image to a screen. One way is by writing a little bit of code to load an image from the client resources and pop it onto a static screen property. This allows you to load any image from the client resources onto any screen. Open the screen designer and click “Add Data Item…” at the top and choose Local Property with a type of Image. I named the property MyImage:
Next drag the MyImage property to where you want it in the content tree. Note, however, that not all areas of the tree will allow you to drop the image if there is a binding already set to a group of controls. The trick is to manipulate the layout by selecting the right groups of controls (i.e. new groups of two rows or columns) and then binding them by selecting the data items you want. For instance let’s say I have an image I want to place across the top of a screen and I want the rest of the controls to appear below that. In that case start, with a Two Row layout and for the top row content select the MyImage property and set the control to Image Viewer.
Then for the bottom row you can select the data item or collection you want to display. If you have a master-detail scenario, then you’ll want more rows. For the bottom row select “New Group” for the content and then change the Vertical Stack to the Two Rows control. This technique lets you build up as many sections on the screen that you want. You can also select Two Column layout for positioning controls side-by-side.
For my example I’m working with data similar to the Vision Clinic walkthrough sample so I’ll also add patient details as a two column layout and then under that I’ll and the child prescriptions, appointments and invoices as a tabbed control of data grids on the bottom row (you can also tweak the layout of the screen at runtime for a live preview). So my content tree looks like this:
Okay now for the fun part – showing the static image on the MyImage screen property. What we need to do first is add the image to the client as a resource. To do that, switch to File View on the Solution Explorer, expand the Client project node, right-click on the UserCode folder and select Add –> Existing Item and choose your image file.
This will add the image as a resource to the client project. Next we need to write a bit of code to load the image into the screen property. Because the loading of the image resource is pretty boilerplate code, let’s add a shared class that we can call from any screen. Right-click on the UserCode folder again and select Add –> Class and name the class ImageLoader. Write the following code:
Public Class ImageLoader ''' <summary> ''' Loads a resource as a byte array ''' </summary> ''' <param name="path">The relative path to the resource (i.e. "UserCode\MyPic.png")</param> ''' <returns>A byte array representing the resource</returns> ''' <remarks></remarks> Shared Function LoadResourceAsBytes(ByVal path As String) As Byte() 'Creates a URI pointing to a resource in this assembly Dim thisAssemblyName As New System.Reflection.AssemblyName(GetType(ImageLoader).Assembly.FullName) Dim uri As New Uri(thisAssemblyName.Name + ";component/" + path, UriKind.Relative) If uri Is Nothing Then Return Nothing End If 'Load the resource from the URI Dim s = System.Windows.Application.GetResourceStream(uri) If s Is Nothing Then Return Nothing End If Dim bytes As Byte() = New Byte(s.Stream.Length) {} s.Stream.Read(bytes, 0, s.Stream.Length) Return bytes End Function End Class
Now back on the screen designer drop down the “Write Code” button on the top right and select the Loaded method. Now all you need to do is call the ImageLoader with the relative path of the image:
Public Class PatientDetailScreen Private Sub PatientDetail_Loaded() Me.MyImage = ImageLoader.LoadResourceAsBytes("UserCode/funlogo.png") End Sub End Class
Run it and you will see the image loaded into the image viewer. You can customize the screen and change how the image is displayed by playing with the Content Size and Stretch properties.
The above technique works well if you have a lot of different static images across screens or if you are just using Visual Studio LightSwitch edition. However if you just have a single image you want to display on all your screens it may make more sense to build your own control and use that on your screens instead. This eliminates the need for any code on the client. If you have Visual Studio Professional edition or higher you can create a Silverlight Class Library in the same solution as your LightSwitch project. You can then add an image control into that library and then use it on your LightSwitch screens.
To make it easy I added a User Control and then just placed an image control on top of that using the designer. I then set the Stretch property to Fill and added the logo into the project and set it as the Source property of the image control using the properties window:
Rebuild the entire solution and then head back to the LightSwitch screen designer. First comment out the code from the Loaded method we added above if it’s there. Change the control for MyImage to Custom Control. Then in the properties window click the “Change…” link to set the custom control. Add a reference to the Silverlight class library you built, select the control, and click OK.
Now when we run the screen we will see the static image control we created:
The nice thing about creating your own control is you can reuse it across screens and LightSwitch projects and there’s no need to add any code on the client.