The PRISM team just published a Prism survey and blogged about it at http://blogs.msdn.com/blaine/archive/2009/04/01/have-you-taken-the-prism-survey.aspx.
If you have worked with PRISM take the survey and let others know about it to get the word out.
I have been running into this odd error off and on for the past week with the code generated by the Linq to SQL designer. I kept on getting Error 1 Build failed due to validation errors in C:\xxx\DB.dbml.... when I tried to build. Thanks to google (a developers best friend) I ran into a blog entry by Rick Strahl that talked about resetting Visual Studio Packages. Well it turns out this is solves my issue but I had to follow these steps to get it to work.
- run devenv /ResetSkipPkgs
- clean the solution
- recompile
I really hope they fix this with SP2 or in VS 10.
I was suprised to find out that Silverlight Data Binding uses OneWay as the default binding mode. This really caught me off guard when I was trying to port some code written in WPF over to Silverlight since all of my TextBox.Text bindings did not have an entry for Mode in the binding statement. The reason of course is that by default TextBox.Text uses a Mode of TwoWay in WPF. In fact many of the common controls like TextBox.Text, ComboBox.Text, MenuItem.IsChecked, etc. have TwoWay as their default mode.
If you are writing code that will be used on both platforms I would suggest adding Mode to the binding statement. It's a pain but it will save you the debugging hassle when your UI is not passing values back to the classes it is bound to.
In many cases while writing software we fail to think about the users of our code. This is often the case when it comes to debugging since most of use feel it's easy enough to just jump into the code and see what's going on. While this is possible it's the simple things in life that sometimes make the biggest difference. Take for instance the case of debugging some code you didn't write. In most cases if you look at a type in the locals window all you will see is a ToString() of the type (see Figure 1) which is not very helpful. To lean more about the type you are forced to drill down into the type looking at the properties to see what's going on. Wouldn't it be nice to see some high level values instead of the ToString() of type? If we take this even further wouldn't it be nice to see some values that the designer of the type thought would be important if you were in a debug session. This is where the DebuggerDisplayAttribute come into play.
Figure 1: Debug Locals Window (click to enlarge)
The DebuggerDisplayAttribute determines how a class or field is displayed in the debugger window eliminating the ToString() default you normally see. Take for instance the code in Listing 1. This is the version of SimpleClass that resulted in the locals window view shown in Figure 1 which as we said was not very helpful. The code in Listing 2 shows how we can add the DebuggerDisplayAttribute to the class to see some more interesting information. In this case we added the attribute with the value we wanted to show up in the value column of the debugger window (see Figure 2). The format "Some Interesting Data = {_hiddenInternalInfo}" consists of two parts: (1) the text to be display and (2) the value from the class {_hiddenInternalInfo} we wanted to see. You are not limited to just one value. If we wanted to see the MyProp1 value as well we could change the entry to look like this "Some Interesting Data = {_hiddenInternalInfo}, MyProp1 = {MyProp1}" and get a result that looks like Figure 3. As you can see it's not really hard to add some additional information to the locals window and help someone who is using your code figure out what's important.
class SimpleClass
{
private string _hiddenInternalInfo;
public string MyProp1 { get; set; }
public string MyProp2 { get; set; }
public SimpleClass()
{
this._hiddenInternalInfo = "Hidden data";
this.MyProp1 = "My intitial data for MyProp1";
this.MyProp2 = "My intial data for MyProp2";
}
}
Listing 1: SimpleClass with no attribute
[DebuggerDisplay("Some Interesting Data = {_hiddenInternalInfo}")]
class SimpleClass
{
private string _hiddenInternalInfo;
public string MyProp1 { get; set; }
public string MyProp2 { get; set; }
public SimpleClass()
{
this._hiddenInternalInfo = "Hidden data";
this.MyProp1 = "My intitial data for MyProp1";
this.MyProp2 = "My intial data for MyProp2";
}
}
Listing 2: SimpleClass with DebuggerDisplayAttribute
Figure 2: Debug Locals Window with More Information (click to enlarge)
Figure 3: Debug Locals Window with a List of Information (click to enlarge)
Here is the Power Point Slide Deck that goes with my RIA talks. Sorry it took me so long to get this out. The Sample RIA Application contains the Rad Bikes demo used.
The application below is a sample application that demonstrates how to create a Web 3.0 application that combines ASP.NET, ASP.NET AJAX 4.0, AJAX Control Toolkit and Silverlight. The application is a fictitious Rad Bikes company that sells bikes and uses SQLExpress 2008 and the AdventureWorks2008 database to show sales territories and details sales figures for salesman in each territory. The home page demonstrates using a custom behavior to add image rotation capabilities to a standard image control. The Sales menu will take you to the sales information page that demonstrates some of the new data binding features of ASP.NET AJAX 4.0 and how Silverlight can be driven via JavaScript. In this case when a territory is selected the Silverlight portion of the page (the bottom portion) will be updated with sales information for that territory using the HTML Bridge that is part of Silverlight. I have an upcoming article tentatively titled Building RIA Applications for Web 3.0 using the Microsoft Platform in .NET Developers Journal that talks more about how this application works but until then feel free to party on the code.
Home Page (select image to enlarge)
Sales Page (select image to enlarge)
Setup Details
The application has a few steps that you need to perform before you can run it.
- The application has a vSalesSummaryViewScript.sql script located in the root directory that needs to be run against the database to create a view not included with AdventureWorks2008.
- The application also uses the following connection strings that will need to be updated if they don't match your installation.
<connectionStrings>
<add name="AdventureWorks2008ConnectionString"
connectionString="Data Source=.\SQLExpress;Initial Catalog=AdventureWorks2008;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Once you have done all of this the application should work like a charm.
Application Download
RIA Sample Application
Over the next few months I will be covering SoCal doing a talk on Rich Internet Applications (RIA) using ASP.NET AJAX 4.0 and Silverlight. The inspiration for this talk comes from the convergence I see between some of the Web 2.0 technologies and Silverlight and the coming of age of Web 3.0. I am hoping I will be able to cover some of the challenges you will face when interacting with these technologies and provide some guidance as you move forward creating applications of this type.
Information and Dates
Title
Building RIA Applications for Web 3.0
Description
Web 3.0 will prove to be the incarnation that moves us into highly interactive applications that exploit the advances in UI graphics, module web applications and the ever increasing internet connection speed to provide users with an online experience never seen before. In this session we will take a look into how some of the new Microsoft Web technologies (ASP.NET AJAX 4.0 and Silverlight) will play a role in this new frontier. First will take a look at ASP.NET AJAX 4.0 and how some of the new features like templates and data binding are contributing to a pure client-side story for web development. Then we will dive into Silverlight exploring the extensive UI model, robust communication stack and reliance on .NET and how these features provide a robust environment for creating truly interactive module web applications. Finally we will look at how the HTML Bridge in Silverlight provides interaction between the dynamic language world of JavaScript and the static language world of .NET and how to best work in these two environments to provide a rich Web 3.0 experience.
Dates and Locations
Tuesday September 22nd
San Diego .Net User Group
www.sandiegodotnet.com
Saturday October 25th
SoCal Code Camp (USC)
http://www.socalcodecamp.com/
Tuesday November 4th
San Diego .Net Developers Group
http://www.sddotnetdg.org/
Tuesday November 11th
Disney .NET Developers Group
Tuesday November 11th
Silverlight User Group SiG
http://www.ocdotnet.org/SIGs/WPFSliverlightUserGroupSIG/tabid/175/Default.aspx
So I am using the new Data Designer in VS 2008 to create my LINQ to SQL DataContext and associated data classes and one of the first thing I wanted to do was to send back one of these "data classes" to an AJAX client via a AJAX-enabled web service. I write the code to return a SalesTerritory class "yes I am using the infamous AdventureWorks database" and hook up all of the associated code and try to run the thing. To my surprise things didn't work. I open up Nikhil Kothari's Web Development Helper to find out I have a serialization error.
"Type 'RIASilverlightWeb.Data.SalesTerritory' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.
Well this really bummed me out. I sure the heck didn't want to decorate all of that generated code with DataContact/DataMember stuff. To my surprise MS has made this easy. All you need to do is go to the properties of the designer and set the SerializationMode to Unidirectional (see below).
What this does is decorate all of your classes with the DataContract attribute and all of your properties with the DataMember attribute. Once you do this the data can be serialized.
This can also be done with SQLMetal using the /serialization:Unidirectional command flag.
Man Betrand LeRoy and his team are really cranking this stuff out. Following on the heels of last months release they now have a new ASP.NET AJAX Preview 2 release on CodePlex. Here are some of the new features:
- Observer Pattern. This change makes a plain JavaScript object or array emit change events. For example, you can use the observer pattern to enable live binding of plain data to UI, where changes in the UI are propagated to the data and vice versa.
- Conversion functions on Binding. Binding now supports a convert function and a convertBack function.
- Chained bindings. It is now possible to bind A to B and B to C, and have changes to A propagated to C.
- Reactivating UpdatePanel controls. UpdatePanel controls within an activated region (a region with declarative markup) are reactivated after partial updates.
- Markup extensions now support nested {{ }} expressions. This may require a rewrite of Preview 1 markup extensions.
I am going to be jamming on this stuff over the weekend (yea I know it's a holiday weekend). Great job guys!
I was totally bummed to get the following email from Lutz Roeder today. It seems that Reflector the tool I am come to love and cherish is now under the control of Redgate software. I hope they continue with the tradition that has made this application one of the must have tools for .NET developers.
Lutz email:
After more than eight years of working on .NET Reflector, I have decided it is time to move on and explore some new opportunities.
I have reached an agreement to have Red Gate Software continue the development of .NET Reflector. Red Gate has a lot of experience creating development tools for both .NET and SQL Server. They have the resources necessary to work on new features, and Reflector fits nicely with other .NET tools the company offers.
Red Gate will continue to provide the free community version and is looking for your feedback and ideas for future versions.
For news and updates on Reflector, sign up for the .NET Developer’s Newsletter from Red Gate. To find out more about the agreement, see the interview on Simple Talk.
Dave Ward of Encosia fame is having a coding contest and giving away three copies of our book. Stay tuned to his awesome blog for more details on this and much more related to ASP.NET and ASP.NET AJAX.
As I am digging more and more into Silverlight I find more and more features I have come to love in WPF that are just not there. One feature is Attached Events. In WPF I can do something like this in XAML.
<StackPanel Height="25" Orientation="Horizontal" ButtonBase.Click="StackPanelCommon_Click">
<Button Name="Yes" Margin="5,0,5,0" Content="Yes"/>
<Button Name="No" Margin="5,0,5,0" Content="No"/>
<Button Name="Cancel" Margin="5,0,5,0" Content="Cancel"/>
</StackPanel>
In this scenario the StackPanelCommon_Click handler will handle the click event for the Yes, No and Cancel buttons. Inside this handler I can add code to determine the particular button selected and implement logic accordingly (see below).
private void StackPanelCommon_Click(object sender, RoutedEventArgs e)
{
Button button = e.Source as Button;
if(button != null)
{
switch (button.Name)
{
case "Yes":
//some logic goes here
break;
case "No":
//some logic goes here
break;
case "Cancel":
//some logic goes here
break;
}
}
}
But when I try this in Silverlight I get the following error.
So what the heck is going on here? It turns out that UIElement does not support the AddHandler method which allows you to add handlers to the UIElement.
I hope in future versions Microsoft can add this into Silverlight to help promote more concise coding approaches since the alternative is similar to the old days gone by.
Betrand Le Roy blogged about the released the Microsoft ASP.NET Ajax Road Map
which describes some of the new proposed features of ASP.NET AJAX. One of the topics in this document centered around working with data on the client which is something I have been anticipating for quite a while. Up until now working with data on the client has been a mixed bag of solutions that never seemed to completely gel (remember the xml-script stuff) and approaching the problem with UI Templates, bi-directional data binding and new "mixed mode" controls that work with data on both the client and the server seems like an approach that finally gels.
UI Templates
Templates have been around for quite a long time in ASP.NET and moving this concept to the client makes life much easier. I can remember building up HTML fragments on the server and injecting them into a div using div.innerHTML which was always fun during data changes. A template approach (see below) simplifies this dramatically. The {{ ‘products/’ + id }} syntax which basically says put the value of the id property into this expression will take a little getting use to but is similar enough with other markup syntax like XAML that it shouldn't be to hard to pick up. The associated JavaScript code adds a behavior to the template that associates the data, template and element to facilitate repeated data binding.
<div id=”repeater1”></div>
<div id=”template1” class=”sys-template”>
<h2><a href=”{{ ‘products/’ + id }}”>{{name}}</a></h2>
<p>{{description}}</p>
</div>
<script type=”text/javascript”>
Sys.Application.add_initialize(function() {
$create(Sys.UI.DataView, {
template: $get(“template1”),
data: myData
}, {}, {}, $get(“repeater1”));
}
</script>
There are other examples in the roadmap that show how to do this all declaratively by including various xml namespaces. I like this approach better since its closer to the way XAML works which for someone who moves between the two often helps keep my mind thinking consistently.
Data Binding
I am excited to see a new approach to client-side data binding in this new roadmap. In the early SDRs I thought the xml-script stuff was odd and didn't feel that the approach would be a viable one. I am glad to see this has been revisited. I hope this approach will limit the use of update panels for partial page refreshes and possibly be incorporated into the ASP.NET MVC stuff to provide a clean way to do more work on the client. The HTML fragment below demonstrates the binding syntax {Binding flight, mode=twoway} which is identical to how XAML does it. This type of binding allows for bidirectional binding which is an absolute must when working with client-side data. I am glossing over a lot here so read the roadmap for a lot more information on how all of this code works.
<body xmlns:sys=”BLOCKED SCRIPTSys” xmlns:dv=”BLOCKED SCRIPTSys.UI.DataView”>
<div id=”tripList” sys:attach=”dv” dv:data=”{{myData}}”
dv:template=”{{$get(‘template2’)}}”></div>
<div id=”template2” class=”sys-template”
xmlns:ac=”BLOCKED SCRIPTSys.UI.AutoComplete”
xmlns:wm=”BLOCKED SCRIPTSys.UI.Watermark”
xmlns:dp=”BLOCKED SCRIPTSys.UI.DatePicker”>
<input type=”text” sys:id=”{{ ‘airport’ + $index }}”
sys:attach=”ac,wm”
ac:serviceUrl=”airportList.asmx”
ac:minimumPrefixLength=”{{1}}”
wm:text=”Type the name of an airport”
value=”{Binding airport, mode=twoWay}” />
<input type=”text” sys:id=”{{ ‘flight’ + $index }}”
value=”{Binding flight, mode=twoWay}” />
<input type=”text” sys:id=”{{ ‘date’ + $index }}”
sys:attach=”dp”
dp:lowerBound=”{{ new Date(1970, 4, 21) }}”
dp:upperBound=”{{ new Date(2050, 1, 1) }}”
value=”{Binding date, mode=twoWay}” />
</div>
Client Data Sources
The roadmap also talks about support for something called "live binding" where changes to data automatically propagate to update the rendered UI.
To support this Microsoft expects to implement a Client Data Source that can:
- specify a source of data, such as an ADO.NET Data Service.
- request data from the source.
- cache data.
- save changes back to source.
- Expose methods such as insertRow.
- provide collection-change events on cached data.
- Client-Side and Server-Side Data as One
if they can pull this off the client development will be totally awesome!
Client Data and Server Data
I am also glad to see that the client data approach is combined with a server data approach. Many times a pure client-side approach requires a developer to go get data from the server after the page has been rendered. This has always seemed like a inefficient approach. In the early days of ASP.NET AJAX having a combined client/server data solution was one thing I had mentioned in the SDRs. It seems the ClientDataSource, ClientDataSourceExtender and the ClientDataView server controls will solve this problem for us providing the ability to work with data from both locations using a clean approach.
Summary
I am really excited about what is coming out of the ASP.NET Team in this area and looking forward to working with the bits. With Silverlight all the rage I am glad to see that we still haven't forgotten that for real "reach" scenarios HTML and JavaScript are still going to be needed.
This week we upgraded our blog server to the latest and greatest Community Server edition. Since we waited so long to move we were forced to create a new location to host our blogs which is now team.interknowlogy.com which will bring you to your favorite IK blogger's. We hope you like our new site and we hope the spammers hate it.