VideoWiki – Step 0

 

The neurons in your brain have a basic structure of an axon (the finer cable like projections) and dendrites (the branches) and the soma (the central part of the neuron).  The axon emerges from the soma at the axon hillock where there is the greatest density of voltage dependent sodium channels. The interesting thing about a neuron is that it is an “all or none” mechanism – that is, like the binary underpinnings of computing, either it fires or it doesn’t.  The interesting thing about the axon hillock is that the action potential has to build quite a bit before you overcome the threshold for that neuron to fire. The action potential builds by other neurons stimulating it and it is the most easily excited part of the neuron. Yet, it is almost as if there is a built in resistance to firing, the hillock acts as a guard against impetuous firing, but once that resistance is overcome… zap!

I am very much like that when it comes to starting a project. I  have an enormous metaphorical axon hillock that stands in the way of getting going, and a great deal of stimulation from half baked ideas is required before I finally fire. I’m not intimidated by a blank sheet of paper (in fact, that is my favorite starting point) but I like to let lots of ideas cook for a while before I choose my path (each time I do I can hear doors closing and gates slamming on all the paths I didn’t take).

 Chain Reaction

Keeping The Chain Reaction Alive

For a nuclear bomb to work there must be chain reaction in which one reaction causes an average of more than one additional reaction so that there is a rapid (literal) explosion of reactions. 

All of this happens very quickly, and one anecdote I particularly like from Richard Rhodes’ brilliant book The Making of the Atomic Bomb  is that the time criticality for the necessary nuclear reaction at Los Alomos was found to be 30 nanoseconds, and so he coined the term shake to mean 10 nanoseconds, thus criticality was three shakes (of a lambs tail).

But I digress. The analogy here is that early in the fission reaction it is fairly easy for the chain reaction to stop if there is not enough propagation of reactions, just as early in a design/development process it is easy for the project to become shelved through becoming either distracted by something else or stymied by indecision.

 

Keep Moving

The solution, especially at this critical phase, is to keep moving, letting one piece of the project create other pieces and overcoming obstacles by force of will and by momentum. Thus, I will make it my business to create blog entries (and soon videos and more) that address this project with great frequency, especially early in the project.

Project Challenges

My greatest challenges right now are

  1. Organizing the parts of the project
  2. Creating a starting schedule
  3. Matching the project to the only partially related goals of demonstrating Silverlight 3 features
  4. Making sure that the VideoWiki project and my other projects (this blog, twitter, videos, tutorials and the new book) all leverage (but do not duplicate) one another or there is no prayer of getting it all done.

To do this I have to take a number of risks and the top three are:

  1. Publishing a set of tasks that I know will change over time
  2. Publishing a schedule that will change over time
  3. Writing code for the project before anything is certain (“you start coding, I’ll go get the spec.”)

The next related blog entry will have my preliminary task list (posted later today or tomorrow)

 

      Previous: The VideoWiki Project                                     Next  VideoWiki Step 1

Posted in z Silverlight Archives | Comments Off on VideoWiki – Step 0

Designer TinyUrls

It turns out, as many of us have known but not really focused on, that you can ask TinyURL.com to give you a custom url if it is not otherwise taken. We know what has happened with full URLS, and we know (according to their management) that TinyURLs never expire. Since a custom tinyURL is easier to remember (it is easier to remember that my blog is at http://www.tinyurl.com/JLBlog than it is to remember that it is at http://www.tinyurl.com/cqla8s 

CustomTinyURL

Thus, I predict, with some confidence that having a custom URL will become valued, and then scarce, and then valuable.

Not wanting to being either left out or piggish, I’ve scoffed up a few I’d like to have before the (self-fulfilling prophesy induced?) rush:

http://www.tinyurl.com/JLBlog   – links to my blog

http://www.tinyurl.com/SLGeek  – links to my blog

http://www.tinyurl.com/VideoWiki  – links to the entry point on my new project on VideoWickis

http://www.tinyurl.com/JLTwitter – links to my Twitter home page

http://www.tinyurl.com/JLPersonal – links to my personal blog and LiveSpace

http://www.tinyurl.com/JLBooks – links to my reading list

http://www.tinyurl.com/JLReviews – links to my reviews page

 

There Ain’t Nothin’ Like A Domain

Lots of things in life are beautiful, but brother,
There is one particular thing that is nothin’ whatsoever
In any way, shape or form like any other.
There is nothin’ like a domain,
Nothin’ in the world,
There is nothin’ you can name
That is anythin’ like a domain!

South Pacific (more or less)

 

On a somewhat related note, GoDaddy.com has some incredibly inexpensive domains if you are willing to settle for funky extensions like .info or if you don’t watch carefully as they assemble your shopping cart!

Thus, I bought up http://www.ExampleCodeQuality.info (which links to the page explaining the idea) and http://www.VideoWiki.info which points to the first page in the new VideoWiki project.


This work is licensed under a Creative Commons Attribution By license.
Posted in z Silverlight Archives | Comments Off on Designer TinyUrls

VideoWiki – A Open-Book Design-To-Delivery Silverlight 3 Project

VideoWiki Project and Meta-Project – Launch

I am pleased to announce a new long term project that I am launching here on Silverlight.net, principally on my blog, but that will reach into my videos and beyond.

This note is the entry point to the project; whenever you are joining us, this is the place to start.

In this note,  I will provide the initial goals and the general approach.

A Project and a Meta-Project

The Project is to build a meaningful, useful, exciting application in Silverlight 3, from design to delivery, demonstrating a wide range of Silverlight techniques, best practices, and more.

The Meta-project is to demonstrate and document this entire process as openly as possible;  maintaining a running commentary on the project and documenting the process and the lessons learned, including design, meetings, new techniques,  mistakes, victories, changes in direction, improvements, distractions, and all the other issues that arise.

Keeping Your Eyes On The Prize

The Motto of this project, which will appear frequently is this:

The VideoWiki Project:  Our Goal Is not to create a great product, our goal is to create great programmers.

This key distinction will drive some potentially controversial decisions along the way (e.g., to stub out some areas that might be important in a final product but are not immediately relevant to learning something new).

It happens that I believe what I want to build is exciting and interesting enough that it may make sense to bring all the way to completion, in this forum or another; but that is not the proximate goal this effort.  That said, the closer we stay to a spec-driven real-world scenario, the more valuable the experience will be.

The VideoWiki Project

We will be building what we believe to be the world’s first VideoWiki.  A VideoWiki allows you to associate keywords with every moment of a video, and links with every keyword. More, a VideoWiki allows you to have multiple sets of such associations, built by different sets of people and targeted at different audiences.

VideoWiki

We start with Hyper-video: Imagine that you are watching one of our videos and as you watch, a list of all the topics being mentioned is scrolling by in an adjoining window. If you click on a topic ,the video pauses while a list of links appears in a new window. Click on a link and you are taken to related videos or blog entries or tutorials for additional information.  

Extending Hyper-Video to the VideoWiki

The markers will be added at run time. The links will be loosely coupled to the markers. This flexibility means that a given video can have more than one set of markers, and a given set of markers can have more than one set of links.  For now, I’ve coined the word Wick for the combination of a set of markers with a set of links, and the key difference between hyper-video and a videoWiki is that anyone can create a Wick for any Video. Over time, Wicks might be differentiated in any number of ways:

  • Targeted at skill level
  • Targeted at domain (animation for game programmers vs. animation for business programmers)
  • Good Wick creation is a skill and an art, some Wick creators might have a following

Successive Approximation

I will approach the creation of the VideoWiki project from the “get it working and keep it working” school of programming,  with an eye on finding those aspects of the project that are most likely to bring out interesting aspects of RIA in general, and Silverlight 3 in particular.

In the short term at least, some areas will be fully developed, others will be stubbed out and only returned to if the project’s momentum carries us there.  Similarly, depending on the availability of people with certain skills (most especially the availability of folks from the Expression group) we will explore various areas as opportunities arise (I have a couple guest collaborators lined up who will add great value as we go).

High Priority Areas.

Among the skills and techniques that I hope to demonstrate in the first few months are:

  • Silverlight 3 Layout controls
  • Media Player, Expression Encoder, Markers, Injection
  • Rich controls and new  Silverlight Toolkit controls
  • Animation (both storyboard and procedural) and the Silverlight Layout System
  • Out of Browser Experience
  • Data Validation
  • Templating, and the VSM
  • Custom controls, Dependency properties and the States and Parts model
  • Effects, Pixel Shading, 3-D, 3-D Animation, PlaneProjections
  • Save file and Isolated Storage
  • Messaging
  • Various new Data techniques including aspects of the Entity Framework and Data Services

A Special Role for How-Do-I Videos

A key feature on our site is the rapidly growing set of How Do I videos that typically run about 20 minutes and cover a specific topic in either a single video or a short set of 2-3 videos. I will incorporate videos into this project, but in a way that has not been attempted before: creating videos that work both as stand-alone single-topic videos and as illustrations for the project. 

Done properly, readers who are following the project should find the videos to be an integral part of the documentation, and users who are not following the project should find the videos stand on their own with no need to be aware of any aspect of the project at all. That is the theory, but as my old boss, Pat Johnson used to say: “In theory, theory and practice are the same, but in practice they never are.”

Following (and ignoring)  the Project in my blog

The dual nature of the videos will be brought into my blog so that those who are interested can follow along easily and those who are not interested in the project can find the information they want without feeling that the project has “taken over.”

I’ll do this not by segregating the project but by by adding two links in the sidebar: VideoWiki Start (which will bring you to this entry ) and Videowicki Latest which will bring you to the latest entry in the project

and by leveraging two innovations; one already in place, and one new.  

Each entry will have Next and Previous links, so that those who want to follow the project can thread their way through to the related messages easily.

 

 

Dual Purpose Mini-Tutorials

Much as the videos will be called upon to serve both those following the project and those who are not, so will the project’s mini-tutorials. To accomplish this, I’ll divide each of these into three easily distinguished parts:

Part I – Project Motivation– What we’re up to, what our goal is, how what we’re about to do fits into the project

Part II Tutorial – A stand alone mini-tutorial on a useful Silverlight skill that one can read without following the project (an example of what I mean by a mini-tutorial can be found here and here, though these were not part of the project).

Part III Project Integration – fitting what was shown in the tutorial  into the project

(Not every entry will be this rigid, but you can see that my goal is that, as with the videos, the blog entries can stand on their own for those who are not following the project.)

Frequency

While I don’t want to lock myself into a specific schedule,  if this project is going to maintain its momentum I would expect that Project-related entries will be fairly frequent. That said, there are many other topics to blog about and flexibility will be essential.

Participating

I can imagine some developers wanting to participate in this in various ways.  Let me start by saying that I’m eager for feedback, suggestions and constructive criticism at all times and will read these promptly and respond as diligently as I can.

That said, just reviewing code suggestions and submissions can quickly become a full time job, and I don’t envision this as an open-source project (I simply don’t have the bandwidth to manage that).  As the project evolves, I can imagine that some folks might want to take on implementing some part of it, and I look forward to figuring out how to make that work.

Next Steps

Rather than risk being caught in design paralysis, look for an entry very soon that implements one or more small parts of this project. I’m a big believer in overcoming the high resistance to new projects by building something. I understand the value of design, and the risk of coding yourself into a corner, but I also know the risks of too much hand-wringing, and, especially in this case, I will almost certainly err o the side of “build it to throw it away” rather than “measure twice, cut once.”

On a personal note, this is a project I’ve been thinking about for a very long time; it is the first major addition to my efforts as Silverlight Geek in a while and I’m quite excited about it. But it is an experiment: if it meets the needs of the community, then we’ll build on it; if not, then we’ll kill it and try something else. For now, I look forward to the opportunity this affords to tackle larger and more complex problems within a more realistic context.

                                                   Next: Step 0


This work is licensed under a Creative Commons Attribution By license.
Posted in z Silverlight Archives | Comments Off on VideoWiki – A Open-Book Design-To-Delivery Silverlight 3 Project

The New Microsoft Mouse

I had a little trouble unpacking my new mouse

 

arc

 

But once I did, I really like it. Very comfortable and very nice looking. (no wise cracks about looking for the apple logo, thank you).  I’m impressed by the willingness of Microsoft to do this; and very pleased. Now, if we can get a package I can open without a box cutter and a machete….


This work is licensed under a Creative Commons Attribution By license.
Posted in z Silverlight Archives | Comments Off on The New Microsoft Mouse

Why DataBinding With ComboBoxes is NonTrivial

…and Why Coding Is So Much Fun

iStock_BoyWithBrainXSmall A Gonzo Adventure In What You Can Learn When You’re Not Doing What You Are Supposed To Be Doing And You’ll Be Done In Just A Minute, It Almost Works

 

[Read the VB version of this post here

 

 

 

Two days ago I thought I was late getting the code done for my latest tutorial (it turns out that I was actually early but that is a different saga).  I got up early and swallowed lots of pills and drank lots of coffee and took a short nap and then came into the office and sat down at the computer and said, “OK, I just need 20 pages on 3d in Silverlight 3; piece of cake. But anyone can write a tutorial on 3d, what I want to do is show how it fits into writing something real. It isn’t just a toy for little kids, this thing has sharp edges, a person could hurt themselves, we want to put this in context…”

Now, the coolest use of 3d I happened to have seen in the last six or seven minutes was a free program that gets the lyrics for whatever you’re listening to. Its entire UI (or UX as we RIA cognoscenti call it)  is a panel about 400 x 600 pixels. This is nearly entirely filled with scrollable lyrics but there are a couple small icons, including, in the lower left hand corner, a very attractive italicized “i”

If you hover over that seductive little i, it lights up invitingly. Click on the i and hey! voila! the panel rotates 180 degrees revealing its “back” where you can find settings and other cool stuff that you don’t need every day but is very handy to have easily available.

When you finish playing with the settings and have put back all the things you broke, you click and the panel rotates back.  Perfect.  Useful, elegant, space saving and classy.  I want one. More urgent:  I want to build one.

Zo!  That is the next tutorial, but that is not what I’m writing about here.

What I’m writing about here is what happened when I set out to build one, that I did not intend, and was not part of the project and I had no business spending time on. it was long ago and far away….

I had chosen to make my panel databound, and because I was listening to music at the time I was writing the code, I decided that the cards would provide basic information about a musician on the front, and the musician’s bio on the back.

To insinuate a tenuous business connection I created an Employee class to hold all this information (who knows, maybe these guys work for my record company?), and I used the same fields you would (more or less):

public string FullName { get; set; }
public string NickName { get; set; }
public DateTime Birthdate { get; set; }
public string Locality { get; set; }
public string Phone1 { get; set; }
public int Phone1Location { get; set; }
public string Phone2 { get; set; }
public int Phone2Location { get; set; }
public string JobTitle { get; set; }
public string JobNickName { get; set; }
public double JobLevel { get; set; }
public string Salary { get; set; }
public string Performance { get; set; }
public string Bio { get; set; }

Now, this was certainly not the final set of properties, and there was much to fix, but as I created the UI for the phone numbers, it was blazingly clear to me that I wanted the phone type to be in a combo box

ComboBox

That was when the trouble began.  When you chose a new artist all the fields changed…. except the Phone Location (cell, home, etc.)

The more I looked at it the more baffled I became. Set aside that the code was a quick hack with insufficient decoupling of UI from data, it didn’t even work.

After a while this became the night’s obsession, culminating in my doing what I always tell others to do but never quite get around to doing myself: write a tiny program that demonstrates the problem in isolation and ask for help.

Thus was born: ComboBoxProblem.xaml

   <UserControl x:Class=”ShowTheProblem.MainPage”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
    Width=”400″ Height=”300″>
   <StackPanel x:Name=”mySP”>
      <TextBlock x:Name=”Phone”
                 Height=”20″
                 VerticalAlignment=”Bottom”
                 Text=”{ Binding Phone, Mode=OneWay }” />
      <ComboBox x:Name=”PhoneType”
                HorizontalAlignment=”Left”
                Width=”100″
                VerticalAlignment=”Bottom”
                SelectedIndex=”{Binding PhoneLocationID, Mode=OneWay}”
                ItemsSource=”{Binding}”>
         <ComboBox.ItemTemplate>
            <DataTemplate>
               <TextBlock x:Name=”PhoneTypeItem”
                          Text=”{Binding Location}” />
            </DataTemplate>
         </ComboBox.ItemTemplate>
      </ComboBox>
      <Button x:Name=”mybutton”
              Content=”Press Me”
              Margin=”10″ />
   </StackPanel>
</UserControl>

I’ll spare you the supporting code (I hate showing broken code) but I posted this on an internal list and immediately got back two interesting answers: there’s a bug in combo box (there isn’t) and if you set the Mode to TwoWay instead of OneWay everything works.

The Great White Whale

Now I know a Great White Whale when I see one, so call me Ishmael and I was off, spending much of the rest of the night trying to figure this out, and realizing as I went that I truly hated the fact that the Person object  had to know so much about the phone location collection that populated the ComboBox.

It turns out that there were a number of interlocking problems here. Mike Hillberg (a Principal Architect at Microsoft) pointed out that with one-way binding as soon as the control changes SelectedItem, the binding is replaced with the new value.  He also pointed out that I/we were having the person’s GetPhoneLocation return new objects, and just because two objects have locations set to the same string (e.g., “Home”) doesn’t mean the two references point to the same object in memory. (yes, yes, but by then it was very late).

His excellent blog post got me most of the way towards where I needed to go, but I rebelled at the idea of imposing WPF semantics on Silverlight, and I really wanted to constrain the values so that they were self-identifying; that is I wanted more of an enumeration than a class.

Another Microsoftie offered his solution, which I liked very much but his approach included the assumption that the person object would contain an ID that was an offset into the collection of phone numbers used to populate the combo box. That was where I choked.

How To Make An Enumeration Behave Like A Collection

What I wanted was to use an enumeration, with all the wonderful Intellisense support and the intuitive scoping it provides. But you can’t hand an enumeration to the ItemsSource property of a comboBox, nor can you treat enumerations as strings (at least, not without a little work).

After a bit of tinkering, (and then a little hammering, followed by some smashing and yelling)  the solution that finally caught the leviathan (though I’m afraid ol’ Starbuck was never seen again)  was this:   

  1. Create a class that represents one location (so that you can have a collection of said locations, so that each member of the combobox can be an instance of that class).
  2. Obtain the enumeration semantics by giving the class a single member that is an enumerated constant.
public enum PhoneLocationEnum
{
Home,
Office,
Cell,
Other
};
public class PhoneLocation
{
public PhoneLocationEnum Location { get; set; }
}

 

You can now create a collection of these, initializing them with full support from Intellisense,

PhoneLocation2 

I’m so happy.

But I need an ItemsSource

What we need is an observable collection to serve as the ItemsSource for the comboBox. We’d like to add each of the PhoneLocation objects to that collection, but where will that collection live?  What we really need is a class that is a collection of Phone Location objects. Aha!

public class PhoneLocations : ObservableCollection<PhoneLocation>

This sneaky bit of C# makes PhoneLocations a kind of or derived type of Observable collection of PhoneLocaitons and as such fully legal as an ItemsSource. To wire it up I need to create a namespace (local) that points to this assembly and then declare this puppy in the resources section of the Xaml file,

<UserControl.Resources>
<local:PhoneLocations x:Key="phoneLocations"/>

[ Thank you Hamid Mahmood for showing me this bit of Xaml ]

Now, finally, I can put the pieces together, Here is the Xaml

<UserControl x:Class="ComboBoxSample.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ComboBoxSample"
Width="400" Height="300"
Loaded="UserControl_Loaded">
<UserControl.Resources>
<local:PhoneLocations x:Key="phoneLocations"/>
<local:EnumToStringConverter x:Key="converter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel x:Name="mySP" Margin="20">
<TextBlock x:Name="Phone"
Height="20"
VerticalAlignment="Bottom"
Text="{ Binding Phone, Mode=OneWay}" />
<ComboBox x:Name="PhoneType"
HorizontalAlignment="Left" Width="100"
VerticalAlignment="Bottom"
ItemsSource="{StaticResource phoneLocations}"
SelectedItem="{Binding PhoneLocVal,
Mode=TwoWay,
Converter={StaticResource converter},
ConverterParameter={StaticResource phoneLocations}}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Location}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button x:Name="mybutton"
Content="Click Me" />
</StackPanel>
</Grid>
</UserControl>

ComboBox has three important binding-related statements:

  1. The ItemsSource is bound to the phoneLocations that was defined in the resources and thus tied to the observable collection of PhoneLocation objects

  2. The SelectedItem is bound to PhoneLocVal which as you’ll see in a moment is the integer value stored in Person that is directly derived from the enumerated constant for the phone location

  3. The DataTemplate is bound to Location which is the (only) property of the PhoneLocation object and which is of type PhoneLocationEnum

This last point is critical.  At the risk of repeating; we declare the enumeration, then we declare a PhoneLocation class that has a single member whose type is that enumeration, and finally we declare a class that is an observable collection of those objects whose member is of the enumerated type!

Type Conversion

There is a second statement in the resources section of the Xaml that I’ve glided right past,

<local:EnumToStringConverter x:Key="converter" />

This declares a type converter, and we see it invoked in the ComboBox 

SelectedItem="{Binding PhoneLocVal, 
Mode=TwoWay,
Converter={StaticResource converter},
ConverterParameter={StaticResource phoneLocations}}" >

In this declaration we are saying that while we are binding to the PhoneLocVal property we don’t expect to know how to display that, and so we’ll need to use the declared converter and, further, we’ll pass in the phoneLocations as a parameter.

The code for the conversion implements IValueConverter, and thus has two methods: Convert and ConvertBack:

public class EnumToStringConverter : IValueConverter
{
public object Convert(
object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture )
{
int phoneLocationAsInteger = (int)value; ;
PhoneLocations locations = parameter as PhoneLocations;
if (locations != null)
{
foreach (PhoneLocation pl in locations)
{
if ((int)pl.Location == phoneLocationAsInteger)
return pl;
}
}
return null;

}

public object ConvertBack(
object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture )
{
throw new NotImplementedException();
}

}

We cast the value we’re given to an integer and the pareameter to a PhoneLocations collection. We then iterate through the collection checking to see if we find a member whose Location when cast to an int is equal to the value we were given. If so, we have our winner, and we return it.  This converts an integer value to a Phone Location while ensuring that we stay within the boundaries of the enumerated constants.

Once I had that, I could sleep.

The complete source code is available here.

womc100

This code was built with Silverlight 3 Beta.

Posted in z Silverlight Archives | 5 Comments

Keeping you informed, and reducing confusion

 

Guaranteed to have the quality of Example Code – Every Time 

WOMC

To keep things a bit tidier here, I’ve consolidated the messages about the Example-Code Quality effort to provide development environment information to a  centralized page that can also be reached through http://ExampleCodeQuality.info

Thanks for your ongoing support 

 

Posted in z Silverlight Archives | Comments Off on Keeping you informed, and reducing confusion

Quick 3-d Update

I mentioned in a previous blog post that I’d posted a two part video on the new 3d capabilities in Silverlight 3. Since then I’ve had a few great conversations with Jeff Paries (who knows more about Silverlight Animation than most people on the planet) and I had the opportunity to think about other, perhaps even better ways to accomplish the same thing.

This has led me to re-focus my next tutorial (forthcoming) on how 3d Animation can be used to add real value to an application (as opposed to making a great demo or a cool but not very useful bit of sizzle).

In the meantime, I did want to point you to Jeff’s latest blog post on using Silverlight 3’s perspective 3d, in which he flips a playing card through two planes and along the way explores some of the finer points of managing (for example) bit-map drop-shadow effects in a perspective transform.

In the small world department, Jeff begins his article by pointing to Corey Schuman’s excellent summary of the fundamentals.  Now, Corey and I met only recently, but he is amazingly talented and enthusiastic, and he and I will co-author  Programming Silverlight 3  (which is something I should be shouting from the rooftops.)

The key change that I did go back and make to my demo code shown in the video (not required, but cleaner) is to remove the code that moves the “back” of the panel in and out of position using a translate transform and replaced it with a change of the visibility:

Revised Storyboard

<Storyboard x:Name=”FlipFrontToBack”>
<DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Storyboard.TargetName=”FormFront”
Storyboard.TargetProperty=”(UIElement.Projection).(PlaneProjection.RotationY)”>
<EasingDoubleKeyFrame KeyTime=”00:00:00″ Value=”0″/>
<EasingDoubleKeyFrame KeyTime=”00:00:01″ Value=”90″/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames BeginTime=”00:00:00″ Storyboard.TargetName=”FormFront”
Storyboard.TargetProperty=”(UIElement.Visibility)”>
<DiscreteObjectKeyFrame KeyTime=”00:00:00″>
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=”00:00:01″>
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames BeginTime=”00:00:00″
Storyboard.TargetName=”FormBack” Storyboard.TargetProperty=”(UIElement.Visibility)”>
<DiscreteObjectKeyFrame KeyTime=”00:00:00″>
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime=”00:00:01″>
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime=”00:00:00″ Storyboard.TargetName=”FormBack”
Storyboard.TargetProperty=”(UIElement.Projection).(PlaneProjection.RotationY)”>
<EasingDoubleKeyFrame KeyTime=”00:00:01″ Value=”270″/>
<EasingDoubleKeyFrame KeyTime=”00:00:02″ Value=”360″/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>

Anger

For those who find complex Xaml tedious to read, here it is in pseudocode:

< Create a storyboard named "FlipFrontToBack">     
   <The first object to target is the stackpanel FormFront />
   <change the RotationY property of the PlaneProjection >
     <When we begin the angle will be 0/>          
     <One second later the angle will be 90/>     
   <Also target the visibility property />          
     <As soon as we start, set it to visible />          
     <At one second, set it to collapsed />
   <We're done with formFront now let's do the FormBack />
    <Start by setting its visibility to collapsed />
    <At 1 second change its visibility to visible />
    <Also change PlaneProjection.RotationY>
     <At one second we'll set its angle to 270/>          
     <One second later the angle will be 360/>     
  <we're done />

Not so bad that way.



Bottom line, we’re still doing our slight of hand when the front panel is at 90 degrees, but instead of bringing in the back panel from offstage, we just swap visibility, which means no matter how big you make your browser you won’t see the man behind the curtain.

The code to go with the new tutorial will build on this a bit.




Posted in z Silverlight Archives | Comments Off on Quick 3-d Update

Toolkit Control – TimePicker

 

 

 

You can learn a great deal about the new TimePicker class with a fairly simple example program that I will lay out and zip through here (a full video on the topic is coming very soon).

ClickOnGetStartedTo begin, you’ll want to download the latest Silverlight Toolkit, which you can easily do by  clicking on Get Started in the left margin of my blog (or on the image to the left) and from our Get Started page, click on number 4, Download Silverlight Toolkit.

That will bring you to the Codeplex home of the Toolkit where you can download any or all of the controls, the source to the controls, and/or the samples for Silverlight 2 or 3.  To get the latest controls, click on the menu item Releases, and then download either or both of the installers.

 

 

ToolkitDownload

The installer will place the libraries in the right location and make adding the resources to your application a snap.

 

Recreating The Example

Create a new Silverlight application (Silverlight 2 or 3) named TimePicker and add two resources: Windows.Controls and Windows.Controls.Input.Toolkit

AddRef

Add a name in the Xaml for “input” and let Intellisense help you choose System.Windows.Controls.Input.Toolkit”.  Set up a grid with five rows and three columns, as shown here,

<UserControl x:Class=”TimePickerBlogSL3.MainPage”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
    xmlns:input=
“clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit

    Width=”800″ Height=”200″>
   <Grid x:Name=”LayoutRoot”
         Background=”White”>
      <Grid.RowDefinitions>
         <RowDefinition Height=”1*” />
         <RowDefinition Height=”1*” />
         <RowDefinition Height=”1*” />
         <RowDefinition Height=”1*” />
         <RowDefinition Height=”1*” />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
         <ColumnDefinition Width=”3*” />
         <ColumnDefinition Width=”2*” />
         <ColumnDefinition Width=”2*” />
      </Grid.ColumnDefinitions>

 

Our goal now is to add a Time picker and to allow the user to set the PopupButtonMode (do you click on the picker or hover over it to make it open) and the PopUp (RangeTimePicker or ListTime). 

ListTime looks like this

popuptime

 

RangeTimePicker looks like this:

 

RangePickerTime

Be Careful with Seconds

To add an interesting twist, the RangeTime popup optionally allows you to set the seconds while the Listtime does not, though it does allow you to set the number of minutes between each interval. (For example, I can set the interval to 7 minutes, and the ListTime changes accordingly, as shown in the next image)

7Minutes

Getting Started

With the grid iin place, let’s add a very simple TimePicker control to get started,

 

<input:TimePicker x:Name=”FirstTP”
                  Width=”200″
                  Grid.Row=”0″
                  Grid.Column=”0″
                  Margin=”5″
                  HorizontalAlignment=”Left”
                  VerticalAlignment=”Center” />

Run the program. That’s it, you’re done. Works great.

Of course, it would be good to get the value from the time picker (you know, just to show we can).  To satisfy the cynics, we’ll add a prompt in the second column and display the value in the third,

<TextBlock x:Name="TimePrompt"
Text="Time:"
FontSize="18"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Margin="5"
Grid.Row="0"
Grid.Column="1"/>
<TextBlock x:Name="Time"
FontSize="18"
Foreground="Red"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Margin="5"
Grid.Row="0"
Grid.Column="2" />

There are two ways to get the value from the time picker into the “Time” textblock.

In Silverlight 2 (and optionally in Silverlight 3) you can respond to the DropDownClosed event that will fire when the user makes the time selection and the popup window closes

FirstTP.DropDownClosed += 
new RoutedPropertyChangedEventHandler<bool>( FirstTP_DropDownClosed );


void FirstTP_DropDownClosed(
object sender,
RoutedPropertyChangedEventArgs<bool> e )
{
Time.Text = FirstTP.Value.ToString();
}

Element Binding

In Silverlight 3 you can eliminate this event and handler and instead data bind the text element directly to the value of the TimePicker element as shown in this video and illustrated here,

<TextBlock x:Name=”Time”
  FontSize=”18″
  Foreground=”Red”
  Text=”{Binding Value, Mode=OneWay, ElementName=FirstTP}”
  VerticalAlignment=”Bottom”
  HorizontalAlignment=”Right”
  Margin=”5″
  Grid.Row=”0″
  Grid.Column=”2″ />

Setting the Mode and Type

We’ll let the user choose the mode and  popup type with radio buttons,

<!--Pop up mode-->
<TextBlock x:Name="PopupModePrompt"
Text="Style:"
FontSize="18"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Margin="0,0,5,0"
Grid.Row="1"
Grid.Column="1" />
<StackPanel x:Name="PopUpModeStackPanel"
Orientation="Horizontal"
Grid.Row="1"
Grid.Column="2"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<RadioButton x:Name="PopUpModeClickRB"
GroupName="PopUpMode"
Content="Click"
Width="Auto"
Height="Auto"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Margin="10,0,0,0"
FontFamily="Georgia"
FontSize="18"
IsChecked="true" />
<RadioButton x:Name="PopUUpModeHoverRB"
GroupName="PopUpMode"
Content="Hover"
Width="Auto"
Height="Auto"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Margin="10,0,0,0"
FontFamily="Georgia"
FontSize="18" />
</StackPanel>

(I won’t take the space here to show the PopUpBoxPrompt and radio buttons except to point out that they will be on Row 3 and otherwise very similar to the above.)

Optional Input Fields

Rows 2 and 4 are reserved for the input for the “Interval” (which is visible only when the user chooses Popup) and the UseSeconds checkbox (which is visible only when the user chooses RangePicker.) In the following illustration all are visible, a condition that is never seen in the wild,

 

4Rows

We want to display MinutesInterval when the user clicks on Pop Up and hide that and display Use Seconds when the user selects Range Picker.

 

 

 

The only tricky part is that while it is perfectly safe (if meaningless) to have an interval when using the RangePicker, an exception will be thrown if the TimePicker’s PopupTimeSelectionMode is set to AllowSecondsSelection and the TimePicker’s Popup is of type ListTimePickerPopup, so this must be carefully avoided. The place you typically run into this is when the user changes to RangePicker, selects UseSeconds, and then switches back to Popup. So we need to be just a bit careful.

 

Opening Vs. Opened

Like many controls, the TimePicker fires four events related to opening and closing its drop down (there does seem to have been some debate about whether it is a drop down or a pop up!)

  • DropDownOpening
  • DropDownOpened
  • DropDownClosing
  • DropDownClosed

That gives us exactly the level of control we need.

void FirstTP_DropDownOpening(
   object sender,
   RoutedPropertyChangingEventArgs<bool> e )
{
   SetMinutesInterval();
   SetSeconds();
}

We will check (and set) the interval and most important whether we are allowing seconds just before we open the chosen popup (dropdown) and thus when it is certain which one is wanted.

Sequence of Events

the sequence of events, then, is that we present the time picker on the left and two sets of radio buttons on the right, defaulting to Pop Up. We also present a text box in which the user can fill in the Minutes Interval (which we default to 15),

TimePickerStep1

 

When the page is loaded the constructor runs in which we assign to the value of the Time Picker the current time. We also set the event handlers and the initial PopupMode and PopUpType based on reading which radio buttons are checked (in this case, the radio buttons were set in the Xaml).

 

 

 
The Constructor
public MainPage()
{
InitializeComponent();

// initialzie the value to the current time
FirstTP.Value = DateTime.Now;

// radio button event handlers
PopUUpModeHoverRB.Checked +=
new RoutedEventHandler( PopUpMode_Change );
PopUpModeClickRB.Checked +=
new RoutedEventHandler( PopUpMode_Change );
PopupRB.Checked +=
new RoutedEventHandler( PopUpBox_Change );
RangePickerRB.Checked +=
new RoutedEventHandler( PopUpBox_Change );

// time picker event handlers
FirstTP.DropDownOpening +=
new RoutedPropertyChangingEventHandler<bool>(
FirstTP_DropDownOpening );
FirstTP.DropDownClosed +=
new RoutedPropertyChangedEventHandler<bool>(
FirstTP_DropDownClosed );
FirstTP.DropDownOpened +=
new RoutedPropertyChangedEventHandler<bool>(
FirstTP_DropDownOpened );

// set initial modes
SetPopUpMode();
SetPopUpType();
}

At the end of the constructor we call both SetPopupMode (click vs. hover) and SetPopupType (popup vs. range)

private void SetPopUpMode()
{

   // radio buttons are nullable booleans,  check for true
   if (PopUUpModeHoverRB.IsChecked == true)
   {
      FirstTP.PopupButtonMode = ClickMode.Hover;
   }
   else
   {
      FirstTP.PopupButtonMode = ClickMode.Press;
   }
}

SetPopUpType is very similar, but here we also set the visibility of the mutually exclusive user input fields (time interval or number of seconds)

private void SetPopUpType()
{
bool range = RangePickerRB.IsChecked == true;
UseSecondsCB.Visibility = range ? Visibility.Visible : Visibility.Collapsed;
UseSecondsPrompt.Visibility = range ? Visibility.Visible : Visibility.Collapsed;
TimeMinutesIntervalPrompt.Visibility = range ? Visibility.Collapsed : Visibility.Visible;
MinutesInterval.Visibility = range ? Visibility.Collapsed : Visibility.Visible;
   // old c programmer habit, same as if (range == true) for non-nullable bool   
if (range)
{
FirstTP.Popup = new RangeTimePickerPopup();
}
else
{
FirstTP.Popup = new ListTimePickerPopup();
}
}

The construct in the second through fourth lines is the C# ternary operator. You read this line

UseSecondsCB.Visibility = range ? Visibility.Visible : Visibility.Collapsed;

like this:  “if range is true, set UseSeconds.CB’s Visibility property to the enumerated value Visibility.Visible, otherwise set it to the enumerated value Visibility.Collapsed.” 

More generally, you can write

<type> <identifier> = <bool> ? <true> : <false>;

That is, test the boolean and assign the true value to the identifier if the bool evaluates true, otherwise assign the false value.  A simpler example would be

string nickname = IsOver18? “buddy” : “kid”;

which will set the string variable nickname to “buddy” if IsOver18 is true and will set it to “kid” otherwise.

 

Implementing DropDownOpening

As noted above, each time the drop down is opened we call the two methods that set one of the two mutually exclusive states, paying particular attention to the seconds.

void FirstTP_DropDownOpening( 
object sender,
RoutedPropertyChangingEventArgs<bool> e )
{
SetMinutesInterval();
SetSeconds();
}

SetMinutesInterval checks to see if the text box has something in it, and if so it converts that value to an int (ignoring the bulletproofing of testing for invalid values) and then assigns that value to the PopUpMinutesInterval of the timePicker. If the textbox has no value in it, the value is set to 10.  We don’t bother checking to see why type of Popup the user has chosen because there is no harm or foul in setting this when it isn’t used.

private void SetMinutesInterval()
{
if (MinutesInterval.Text.Length > 0)
{
// need try block here!
FirstTP.PopupMinutesInterval =
Convert.ToInt32( MinutesInterval.Text );
}
else
{
FirstTP.PopupMinutesInterval = 10;
}

}

 

SetSeconds has to be a bit more cautious because, as noted, an exception will be thrown if you set the TimePicker’s PopupTimeSelectionMode to AllowSeconds when the Popup type is not RangeChecker. In fact, (at the risk of saying this one more time)  the reason we’ve created this method is to ensure that we’re testing at exactly the last possible moment when the user can no longer change this mode!

 

private void SetSeconds()
{
if (RangePickerRB.IsChecked == true &&
UseSecondsCB.IsChecked == true)
{
FirstTP.PopupTimeSelectionMode =
PopupTimeSelectionMode.AllowSecondsSelection;
FirstTP.Format = new LongTimeFormat();
}
else
{
FirstTP.PopupTimeSelectionMode =
PopupTimeSelectionMode.HoursAndMinutesOnly;
FirstTP.Format = new ShortTimeFormat();
}
}

We only set the PopupTimeSelectionMode to AllowSecondsSelection if two things are true. First, it must be true that the user has requested a RangePicker and second the user has to have checked the checkbox indicating to use seconds,

 

UseSecondsCB

 

While it causes an exception to use seconds with a Popup picker, it is optional to use seconds with a RangePicker and the RangePicker works fine either way as shown below,

 

 

 

 

 

 

RangePickerNoSecondsRangePickerSeconds

 

Adding Formatting

A final touch that is a good example of where small things make a big difference, is that we change the Format property of the TimePicker if we are using second from ShortTimeFormat to LongTimeFormat, and thus show the seconds. You see this in the SetSeconds method, above,

 

FirstTP.PopupTimeSelectionMode = 
PopupTimeSelectionMode.AllowSecondsSelection;
FirstTP.Format = new LongTimeFormat();

Rather than post a complete project (which would require having one for Silverlight 2 and one for Silverlight 3, I’ve opted to post only the xaml and xaml.cs files. For Silverlight3 just copy the Xaml to MasterPage.xaml and for Silverlight to copy to Page.xaml. Be sure to fix up the Namespace names and to add the two references.  The source code is here.

 
 
Posted in z Silverlight Archives | 1 Comment

On Email and Organization

Some people are naturally organized – my wife can (literally) find a receipt from five years ago within minutes. I’m lucky if I can find a receipt from Mix.

HEEEEEEEELP! (serie)

Organization Through Larger Boxes

I recently read a book that suggested that people like me have a tendency to try to deal with chaos by using smaller and smaller compartments and containers, when what we should do is use bigger boxes: stop trying for fine adjustments that you’ll only give up on and toss everything in; then find it when you need it. After all you add a lot more often than you retrieve (particularly true with computers where searching is easy and fast).

Which is why I’ve come to love Evernote

Thus, it was obvious once Scott H. pointed out that he gets by on 5 email folders, and zero automatic rules that my system of 250 subfolders (some four levels deep!) and about 60 rules (with categories and flags) was a recapitulation of the exact same problem.

So now, (after carefully archiving and backing up my existing system) I have the following folders:

  • Inbox
  • Act
  • Waiting
  • Reference
  • To Archive

Touch Things Once

That same book urged that you try hard to touch each piece of paper once (rather than open the envelope, put it aside, then put it in the to be paid, then pay it and put it in the paid to be filed, then file it, etc.) 

Each e-mail item goes to one of the folders above. It only goes to waiting if it is waiting for someone else. Everything in Act gets flagged with a due date. Everything in Waiting gets flagged with a reminder date.  Reference is for things I’m pretty sure I’ll need for a blog, video or tutorial in the near term, and auto-archives in six weeks in case I’m wrong.

The “To Archive” folder is really trash for those of us who are afraid to throw anything away.  Fortunately, 500Gig hard drives are small and inexpensive. I recently bought six. 

That’s it.

I’ll let you know how it works out.

Please feel free to leave comments, your email stories and arm-chair diagnoses below.

Posted in z Silverlight Archives | Comments Off on On Email and Organization

Mix 09 Trip Report

 

It is traditional when you return from a conference to file a "trip report" with your team. What follows is my trip report to you, with an emphasis on what I learned. I will not review, here, all that was discussed about what is new in Silverlight 3, that will come in many postings, videos, etc, but rather I’ll try to report on how the conference affected my own plans for increasing your satisfaction both with Silverlight 2 and with Silverlight 3. 

I have to start, however, by saying that the excitement at Mix was palpable, and the reception was highly enthusiastic, first to Bill Buxton’s extraordinary “Back to the Future” keynote and then to the Gu’s amazing, mind-boggling presentation of all that we were rolling out.  The twittersphere could barely keep up, and the excitement persisted throughout the conference.

keynote2

Plans Arising Directly out of Mix

Speaking personally, as is often the case, much of the value occurred in the halls; in the interpersonal connections and in listening to what folks had to say: what was exciting, frustrating, enticing, meeting or missing expectations.

In addition, as I thought about my role and how to meet my goals for the next six to nine months, it became clear that two adjustments would be critical: more collaboration and more context.  The great news was that Mix also afforded the opportunity to set both in motion.

I’ll explain what I’m doing about collaboration here, and I’ll follow with what I’m doing about context within a couple days.

Collaboration

colaab
(image cropped)

One of the truly remarkable things about the Mix conference is how amazingly open and eager to collaborate people are. I had only to suggest the idea and people were ready to sign up….

  • Jeff Paries (Senior Digital Media Designer at Waggener Edstrom) a true expert will work with me on animation
  • Who could be better than John Papa to work with on Data
  • The founders of colaab – an incredible application they built from scratch entirely in Silverlight that I believe may ultimately be the killer app in RIA are willing to share some of what they’ve learned as object lessons in real world Silvelright
  • I’ll continue to work with Justin Angel and the Toolkit team to keep you up to date on what they’re bringing forward
  • I’ll be working with Microsoft team members with expertise in Blend and related products to focus on how these tools can be put to use by developers
  • And the list keeps growing

Silverlight 2 and Silverlight 3

RequiredVersion As you know, Silverlight 3 is a Beta product with no Go Live license.

We are not going to be so infatuated with the latest and greatest that we stop providing world class information on Silverlight 2.

We’ll try to find the right balance, and as Silverlight 3 moves towards release we will increase the time we spend on it so that you’ll be completely ready.

As you may know, my book Programming Silverlight 2 has been cancelled, but I’m happy to announce that we O’Reilly has committed to shipping Programming Silverlight 3 with Visual Studio 2010this year and I am committed to making it be one of the best books on the market. My co-author will be Corey Shuman.

Lessons we might learn from this year’s Mix

Finally, there are always a few things that can be improved or lessons to be learned. Here are my three observations on that note,

  • Wi-Fi availability was excellent within the conference, but less so throughout the hotel. A lot of us begin to itch if we are away from email for more than an hour or so.
  • Post-conference shut-down: It would be great if the "third place" could stay open for a couple hours after the final session so folks could unwind together and get their last minute questions answered.  If not, next conference, we’ll have to set up a place to fall back to.
  • Predictable Availability: From now on, I intend to make myself predictably available in the equivalent of the third place. I very much enjoyed the informal contacts and discussions and look forward to this as a crucial part of upcoming conferences.

This work is licensed under a Creative Commons Attribution By license.
Posted in z Silverlight Archives | Comments Off on Mix 09 Trip Report

Photo Essay of Mix09

I’ve put together a very small photo essay of my trip to Mix, proving to myself (again) that phone cameras are incredibly convenient, and incredibly limited.

Collage

All in all, it was a blast.

Posted in z Silverlight Archives | Comments Off on Photo Essay of Mix09

Silverlight Toolkit Release

 

Easily lost among all the exciting announcements here at Mix is some great news about the Silverlight Toolkit. 

First, the March 2009 release for both Silverlight 2 and Silverlight 3 is now available here

This release includes six new controls:

The first two are covered in this video, the DomainUpDown in this second video, and the remaining three will be covered in videos I’ll be recording very soon.

You’ll also find that the Toolkit Team has been hard at work creating live examples on the CodePlex site,

 

Truly great.

Posted in z Silverlight Archives | Comments Off on Silverlight Toolkit Release