My Book Has a Life of its Own

Sunday, June 29 2008 - , , - 0 comments

I set out to write a book on data access, services, and Silverlight 2 and stick to those topics faithfully. I have a sticky note on my desk that shows the main topics and the word “thin” as a reminder to myself to stick to the point and keep the book thin  … thin as in not a brick that someone could bludgeon me with if they don’t like the book :)

Data Access with Silverlight 2

When I buy an intermediate to advanced book, I love it when the book gets to the point, shows me what I need to know and skips over the 250 pages of introductory material.  Perhaps a chapter or 2 of intro material is fine, because then I can skip over it if I need to or read it if the material is indeed new to me.

My book is not an introduction to Silverlight. It is not an all encompassing book telling the reader everything there is to know about Silverlight. Rather my book explains what is needed to build data driven applications using the most appropriate tools in Silverlight to accomplish this goal.

This does cause a bit of a dilemma because I feel that you cannot build data driven applications in Silverlight without understanding Dependency Properties and the fundamentals of Silverlight’s data binding. I cover these areas, but to stay true to my sticky note, I cover these topics with a little bit of “why” and a little bit of “how” … and I don’t take 250 pages to cover them.

The bulk of the material is starting to take shape and I just looked at my original table of contents and laughed. Its 90% different at this point :) I mentioned a few weeks ago that I use OneNote to organize my thoughts and my chapters. I would be lost right now without it. I have moved ideas, chapters, created new chapters, and sliced and diced my notes so many times that I cannot imagine how I would stay focused without it. OneNote keeps me writing instead of trying to figure out how to organize myself. it is also a great tool for figuring out what you will be writing about in the next chapter. Which at this point, i am realizing that all i can promise myself is what will be in this chapter and what will follow it in the next chapter.

I am having a good time putting the material together, and other than the DataGrid (whose beta state is not fun), the rest of the material is flowing out pretty well. I am looking forward to seeing the completed work in December later this year (which means I need the bulk of it done by September!). The funny thing is that I am working harder on this this shorter book than I did on any of my books that were twice as long!

Silverlight 2 Binding Modes Diagram

Monday, June 23 2008 - , , , - 2 comments

Here’s a tiny little nugget from my upcoming book. There are always concepts that are just natively drilled into me yet they don’t flow smoothly when I try to explain them. For example take the Silverlight 2 binding modes. You have OneTime, OneWay and TwoWay as options. OneWay is the default and many examples of XAML based binding I see of XAML in both Silverlight and WPF omit the Mode property entirely. But OneTime is not always the appropriate option, either. Read only data is better suited for OneWay while editable data is suited well for TwoWay. Data that should only be bound and displayed when the source is first bound is ideal for OneTime.

There are nuisances to the scenarios, too (aren’t there always?). For example, OneWay and TwoWay bindings rely on the INotifyPropertyChanged interface and its PropertyChanged event being raised. 

OK, so my point is that sometimes explaining these types of situations is more difficult than just showing them with code. I;ve always been more about show me the code and sprinkle a little bit of explanation around it. To me that is so much easier to comprehend than reading a dozens of pages without code or pictures.

image

So I came up with a simple diagram for to help myself explain the binding modes a little bit. Its not the only tool I use (I use code samples, other diagrams, and words too) but its one I start with. I figured I would share it for any who might be interested. You can also find a variation of this diagram in my upcoming book Data Access with Silverlight 2 published by O’Reilly (Dec 2008).

Template Binding with Silverlight – Resource to Resource

Sunday, June 15 2008 - , , - 1 comments

I mentioned a few weeks ago that Corrina Barber is creating some elegant skins that I will be using for my samples in my upcoming book Silverlight 2 with Data Access. Corrina has updated quite a bit with the templates due to the changes from beta 1 to beta 2, throw in some minor tweaks that I am making to them, and they are coming along quite well for the book.

One of the changes I began making is creating a way to have a base color that all the control’s skins can use. For example, Corrina has done a fantastic job making some elegant style templates for the Silverlight controls. The controls were originally written to be in the red spectrum of colors. I wanted to make them use a shade of blue as they base color. So all I had to do was go into the templates and create a single resource for the SolidBrushColor for the shade of blue I wanted and then bind each of the style templates that Corrina created to that resource. For example, in App.xaml I added this resource:

        <SolidColorBrush x:Key="BaseColorBrush" Color="#FF00135B"/>

Then I referred to this resource from the styles in app.xaml, like this:

<!--Button Style-->
<vsm:Style x:Key="ButtonStyle" TargetType="Button">
    <vsm:Setter Property="Background" Value="{StaticResource BaseColorBrush}"/>
    <vsm:Setter Property="Foreground" Value="#FFFFFFFF" />
    …

Every style in app.xaml refers to this base color at one or more locations.

image

This works out great since I want all of the styles for all of the controls to hang off this base color. And if you want to use a different shade of blue or even a different base color like green, purple, or yellow you just change the base SolidColorBrush resource. One of my favorite things about Silverlight development is that Blend and the Visual State Manager tools make it easy for a non graphically inclined developer like myself to actually create slick looking styles. Its a very cool thing!

Corrina is going to post some information on her skins and share some tips on how she created them using Blend and the new Visual State Manager tools. So definitely look out for her posts.

image

Silverlight 2 - Dependency Properties and DataContext

Thursday, June 05 2008 - , , - 3 comments

Today my latest article on Silverlight 2 was posted on Simple-Talk . The article explains the foundations of data binding in Silverlight 2 including the importance of Dependency Properties and  the DataContext. I intend on following this up with future articles on the topic, too.

This article contains a small excerpt from a very early chapter in my upcoming book Data Access with Silverlight 2, by O’Reilly.  I’ll be posting small nuggets on my blog and through articles along the way to give everyone an idea of what’s inside the book. The book is due out late this year, probably December 2008. I’d like to get it out earlier, but there is a lot to write about still that may change in the betas, so its a tough balance.

Data Access with Silverlight 2

Enjoy!

Silverlight 2 Beta 2 This Week!

Tuesday, June 03 2008 - , , , - 2 comments

Somasegar was on-stage today at TechEd and announced that Silverlight 2 Beta 2 is going to be released with a GoLive license this week. This also will include a Blend 2.5 June 2008 Preview and tools to VS2008. I’m looking forward to getting the bits this week and working them into my Silverlight book!

The good news (for me) is that nothing I have written about in the first few chapters of my book has changed. The better news is that there are a lot of improvements to items that I will be writing about in the book, so I get to take advantage of them and pass them along. I was going to write about how to sort and do tricks with the DataGrid using some code I wrote, but now it looks like it is baked in.

Here are some of the highlights for Silverlight Beta 2 from the session:

  • Deep Zoom:
    • improved event driven notifications
    • new XML-based file format for Deep Zoom image tiles
    • new MultiScaleTileSource
  • UI Framework
    • more WPF UI features now in Silverlight
    • enhanced
      • animation
      • error handling
      • automation and accessibility
      • keyboard input
      • performance
  • Networking Support
    • Improved Cross Domain support
    • Security enhancements
    • Upload support via WebClient
    • LINQ-to-JSON is now included (formerly a prototype)
    • ADO.NET Data Services support (aka Astoria)
    • Improved SOAP support
  • Rich Controls
    • Visual State Manager
      • New and easier templating model
    • New TabControl
    • TextBox
      • text wrapping
      • scrollbars
    • DataGrid
      • Autosize
      • Reorder
      • Sort

    Dark Side with Blue Hues

    Saturday, May 31 2008 - , , , - 3 comments

    I have many colleagues who have touted the merits of dark backgrounds in Visual Studio and I have tried several variations, yet I always end up back on white. It is not so much that the background needs to be white, rather it is more that I have never found a good mixture of foreground colors that work well on a dark background. Well, I spent some time this evening trying some new settings out. I was determined to find something better for me ... something that would not bother my eyes nearly as much as the bright white backgrounds. Here is what I came up with:

    image

    It is a mixture of mostly blue, red, green and purple hues that seem to work pretty well for my eyes so far. It is not a true black background either. I found that if I stick to a charcoal background the colors are a bit less striking (to me of course). I like the faded look in general and imagine I will be tinkering with this for a while.

    Here is how some XAML looks using my new scheme:

    image

    The red items are error highlighting from the Resharper styles. I had to tinker quite a bit to get all of the styles to work well, especially since Resharper 4 has its own styles that it injects. Will I keep this theme? Who knows. If you want to try it, I have attached the Dark Side with Blue Hues settings file here. However be warned that you should first backup your settings file before trying any new ones. (This means "try new settings at your own risk")

    I'll be turning it back to normal if I take any screen shots for my chapters or articles, though. No need to force my craziness on the editors :)

    6 Great Tools For Writing a Book

    Friday, May 30 2008 - , , , , - 5 comments

    Someone asked me yesterday what tools I use while writing a book. Organization is absolutely critical to me when writing. I have so many thoughts flying around that its really difficult to keep them all straight. That is why its imperative to have some tools to help organize the book writing process. The publisher provides some templates to write with in Word that are mostly helpful (and sometimes painful :) ). Here are some good tools that I am using while writing my new book Data Access with Silverlight 2 .

    1. Microsoft OneNote 2007

    imageI cannot stress enough how important this tool is to me. It helps me organize my thoughts by keeping track of code samples, ideas for demonstrations, stray notes, chapter flow, and things to come back to. I created a notebook in OneNote for my book and created sections for each chapter. Each chapter has several pages in it with ideas for the chapter. The first page contains the flow for the chapter with all of my ideas for sections in the book, as well as ideas for examples and figures.  The rest of the pages go into detail for each of the major sections. When I realized I had too much information in chapter 2, I simply dragged the content from that chapter section over to the next chapter and I was done. One Note is great for things that pop up while you are writing, but you don;t want to get caught up in a tangent. I jot these down in the One Note notebook and come back to it later. One of the best features of One Note for writing is that you can search all of the content very easily.

    2. Tech Smith's Snag-Itimage

    I am constantly needing to grab screen shots of menu's, windows and other of demonstrations for the book. This tool is easy to use and works very well. Enough said!

    3. Tangible Software Solutions' Instant VB / Instant C#

    These tools help convert code samples from VB to C# and back. It works very well and very fast! I've taken an entire project of a couple hundred C# files and converted from C# to VB and it handled it under a minute! There are some free solutions, but this one is my favorite so far.

    4. Lutz Roeder's .NET Reflector

    This tool is just plain awesome. Its been out for years and everyone knows about it. But for writing a book its great to help show the source code for .NET libraries. I found this especially useful when explaining Dependency Properties in my Silverlight book. Just jump right in, search for the class, and up pops the source code for the method or property you are looking for.

     

    5. PowerPoint

    This tool makes it easy to create simple diagrams for the book. I create the diagrams in a PowerPoint slide deck and use Snag-It to create png files from them. I tend to save each slide for the book in the deck, too. This way I can go back and edit the diagram easily if I need to.

    6. Paper and Pencil

    This is my second favorite tool (OneNote being the first). Sometimes I just need to draw something without thinking about the tool at all. Paper and pencil is second nature to most of us as we can easily jot down an idea and draw it up much faster with a pencil .... fast enough that I won't lose my thought!  My kids even laugh at me sometimes because I carry the pencil behind my ear :)

    Keeping Focused on Silverlight and Data

    Wednesday, May 28 2008 - , - 2 comments

    I'm working with the very talented Corrina Barber who has created several sets of skins for Silverlight controls. The skins are elegant, but not over the top, styles that can be applied to Silverlight controls. Corrina has been gracious enough to help customize a set of styles for the controls in my upcoming book "Data Access with Silverlight 2". They will be freely available with the downloadable code for the book and from the book's web site at www.silverlight2data.com , which I will be setting up in the near future (right now it just points to my same site at www.johnpapa.net).

    The focus of my book is on data access with Silverlight (yeah, pretty obvious from the title) ... it is not on how to make a variety of styles, storyboards and animations. But that does not mean the samples have to be ugly. In fact, there are some very good reasons to make examples that use elegant styles in the book (without giving away too much too early). The styles themselves can involve data binding using markup extensions as I will show in some examples.

    So my dilemma was whether to explain all about styles and how to create them, which can be very involved and consume an entire book, or to stick to the focus of the book ... building data driven line of business applications with Silverlight with concepts like REST, WCF, LINQ, etc. I decided on the latter with the compromise of using some elegant yet simple predefined styles.

    Here is an example of a basic control layout using one of Corrina's styles (the ones in the book are still in process, but this gives you an idea of what I mean):

    image

    Anyway ... while reading a book it often bothers me if the book tries to accomplish everything. usually that results in it covering a lot, yet not in enough detail to really make a difference. Instead I want to to give readers exactly what I promise in depth and in detail. This also allows me to jump into the main topics very early. But that does not mean I can't slip a few bonuses in like this one, too :)

    10 Things to Consider Before Writing a Book

    Tuesday, May 20 2008 - , - 5 comments

    There are several things to consider before you sit down to write a book. But here are 10 I wanted to share because I think they are either very important or not spoken of enough.I've gone down this road many times, but I took a long break between books and instead focused on other areas. Of course I am talking about writing about technology, not Harry Potter #8.

    I am currently in the early stages of writing my new book tentatively titled "Data Access with Silverlight 2". The publishing has not changed much other than that the number of books sold has decreased significantly over the years. In the late 1990's and in to 2000 many decent technical books were selling 15,000 to $25,000 copies. Today most never reach 10,000 copies sold. It was not a money maker back then and certainly is not now. Which leads me to rule #1

    NOTE: Yes, these are completely arbitrary rules, but hey, its my blog so I make the rules today :)

    Rule #1)  Don't write the book with the goal being to make money. You may hit the jackpot, but very few books do.

    Rule #2) Spend a good amount of brain cycles on writing the book proposal. Not only will your publisher appreciate it, but it will help you clarify the purpose of your book, the flow, and what should be included and excluded.

    Rule #3)  Keep the content focused. So many books seem to have everything under the sun between its covers. Let's face it, who wants a 1000 page brick on their desk (unless its a reference only)?

    Rule #4) Use less words to say more. use diagrams, listings, code examples, and other resources to clarify your points.

    Rule #5) Pick good reviewers. This is critical because as the author you will miss problems because you are so close to the material. A good reviewer needs to know the technical material, know how to communicate the problem to you, and most of all ... s/he needs to be available to dedicate some time to help review your book. So choose more than 1 :) And be prepared for making changes based on suggestions.

    Rule #6) Interview the publisher. Talk to several publishers about your ideas. Find out what they think of it, how they would pitch it, review what other books similar to yours they have done. Make sure the publisher believes in your book.

    Rule #7) Do something original. Create a book that grabs the prospective reader's interest and keeps it. The content is the ultimate means to persuade the reader, so keep it focused and create a 1 paragraph "why you should read this book" snippet. If you do your proposal well, you will have this at hand.

    Rule #8) Expect long nights, a lot of effort, and frustration. You know your topic well, that's what made you an expert in the field. But do you know everything about a topic? Of course not. When writing a book you will learn things you did not know previously since you are now covering more of the topic than before. Drink it up, but be prepared for the possible delays that may occur because of it.

    Rule #9) Write a chapter outline, keep notes, do research, organize your thoughts. I use OneNote 2007 to keep all of my notes on a book. I have notebook sections for each chapter and I jot down notes about what I want to cover in words. I also keep a bullet list of topics I want to hit heavily and a bullet list of examples i want to go through. Having a tool to do this is awesome. OneNote is ideal, for me. I used to use paper to do this :). But just organizing yourself really helps keep the flow moving.

    Rule #10) Enjoy it. The book and the readers who enjoy it are the ultimate reward. Enjoy the process as much as you can. If it is fun to write it, it will often read better, too.

    Trying Code for my Book in VB and C#

    Monday, May 19 2008 - , - 2 comments

    I've decided to at least try to put all of the code sample in my Data Access with Silverlight 2 book in both VB and C#. While VB was once my main language, C# has long since been the primary language I use.  Thankfully, there is the tool from Tangible Software Solutions called Instant VB that converts C# code to VB code. It can convert a snippet of code, a file, or an entire solution. Its pretty darn fast too.

    For example, here is a class I created in C# ...

    public class Customer
    {
        private int id;
        private string companyName;
        private Address companyAddress;
     
        public int ID
        {
            get { return id; }
            set { id = value; }
        }
     
        public string CompanyName
        {
            get { return companyName; }
            set { companyName = value; }
        } 
     
        public Address2 CompanyAddress
        {
            get { return companyAddress; }
            set { companyAddress = value; }
        } 
    }

    and here is the code that Instant VB created for me.

    Public Class Customer
        Private privateID As Integer
        Public Property ID() As Integer
            Get
                Return privateID
            End Get
            Set(ByVal value As Integer)
                privateID = value
            End Set
        End Property
        Private privateCompanyName As String
        Public Property CompanyName() As String
            Get
                Return privateCompanyName
            End Get
            Set(ByVal value As String)
                privateCompanyName = value
            End Set
        End Property
        Private privateCompanyAddress As Address
        Public Property CompanyAddress() As Address
            Get
                Return privateCompanyAddress
            End Get
            Set(ByVal value As Address)
                privateCompanyAddress = value
            End Set
        End Property
    End Class

    While this small snippet is easy enough to translate, it really comes in handy when you forget an END statement or a line continuation character or some other language specific syntax (or a squiggly bracket in C#).

    So far its going pretty well as I have only run into a few places where it did not convert the code as I expected it would. But it was easily fixed and I suspect that I had a problem because I was just converting a snippet of code (not even an entire method) and the tool could not determine if it was a property, method, or what. As I continue writing the book I will post more on my experiences with this tool, but so far its been pretty good. I don;t know if I trust it to convert my entire solution just yet, but I will be giving it a try once I have time to go through it all and test it.

    They also have a Instant C# tool that converts from VB to C#, too.

    And yes, this tool is not free :)

    Silverlight Consuming REST Services

    Friday, May 16 2008 - , , , , , - 3 comments

    I just finished writing the first draft of a sample I am including in my upcoming book tentatively titled Data Access with Silverlight 2 by O'Reilly. Without giving too much away yet since the final details of the contract are not set in stone, the application example consumes a REST service, manipulates it through LINQ to XML, and binds it to various controls and some composite controls. The interaction with the REST (REpresentational State Transfer) services is pretty slick and quite easy when using Silverlight and LINQ to XML. Of course there are always issues to deal with, but overall it works very nicely.

    Why use REST? Well, REST services are becoming more abundant on the web. They do not expose a contract like WCF so when you deal with this type of data you can parse the XML using LINQ to XML or some other XML tools (though LINQ TO XML is so smooth why bother with anything else in this case). So this raw XML comes barreling into your Silverlight application asynchronously, LINQ to XML makes it fall in line, and its bound to where it needs to go via XAML.

    Sending data back via REST is also very cool. I've got that working now too. I have to be careful not to go overboard fine tuning the examples though or the book will never get written :) Interacting with REST from Silverlight applications is just one piece of the data access puzzle, but its pretty cool.

    DevConnections Las Vegas - Nov 2008

    Friday, May 16 2008 - , , , , - 1 comments

    I'll be speaking at DevConnections in Las Vegas this Fall along with others Julie Lerman and Paul Litwin. The 3 topics I will be presenting are:

    • Data Access with Silverlight 2
    • Integrating Enterprise Library's Data Access Application Block with your Project
    • Practical Strategies with the Entity Framework

    image

    The past few events have been awesome and getting stronger and more fun each time. If you are planning on attending the conference in the Fall, please stop by and say hi.

    My upcoming book tentatively titled Data Access with Silverlight 2 should almost be available by the conference. I am targeting December, but I am hoping I can pull it off for November.