| Comments

I previously wrote about DataGrid grouping using the declarative model of adding GroupDescriptors.  Unfortunately that feature (the declarative part) never made it to the release of Silverlight 3.  It was pointed out to me that I should update that post and it has been on my //TODO list for a while.  Here’s an update…

First, I’m still using a sample data class of Person as my test data:

   1: using System.Collections.Generic;
   2:  
   3: namespace DataGridGroupingUpdated
   4: {
   5:     public class Person
   6:     {
   7:         public string FirstName { get; set; }
   8:         public string LastName { get; set; }
   9:         public string Gender { get; set; }
  10:         public string AgeGroup { get; set; }
  11:     }
  12:  
  13:     public class People
  14:     {
  15:         public static List<Person> GetPeople()
  16:         {
  17:             List<Person> peeps = new List<Person>();
  18:             peeps.Add(new Person() { FirstName = "Tim", LastName = "Heuer", Gender = "M", AgeGroup = "Adult" });
  19:             peeps.Add(new Person() { FirstName = "Lisa", LastName = "Heuer", Gender = "F", AgeGroup = "Adult" });
  20:             peeps.Add(new Person() { FirstName = "Zoe", LastName = "Heuer", Gender = "F", AgeGroup = "Kid" });
  21:             peeps.Add(new Person() { FirstName = "Zane", LastName = "Heuer", Gender = "M", AgeGroup = "Kid" });
  22:             return peeps;
  23:         }
  24:     }
  25: }

Then my XAML is a simple DataGrid (make sure to add assembly references to your project to System.Windows.Controls.Data):

   1: <UserControl x:Class="DataGridGroupingUpdated.MainPage"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
   5:     xmlns:datacontrols="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
   6:     mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
   7:     <Grid x:Name="LayoutRoot">
   8:         <StackPanel>
   9:             <StackPanel Orientation="Horizontal">
  10:                 <TextBlock Text="Group:" Margin="0,0,10,0" />
  11:                 <ComboBox x:Name="GroupNames" SelectionChanged="GroupNames_SelectionChanged">
  12:                     <ComboBox.Items>
  13:                         <ComboBoxItem Content="AgeGroup" IsSelected="True" />
  14:                         <ComboBoxItem Content="Gender" />
  15:                     </ComboBox.Items>
  16:                 </ComboBox>
  17:             </StackPanel>
  18:             <datacontrols:DataGrid x:Name="PeopleList" />
  19:         </StackPanel>
  20:     </Grid>
  21: </UserControl>

Notice the xmlns:datacontrols declaration at the top.

Now since we can’t do the grouping declaratively as in my previous sample with Silverlight 3 beta, here’s how we could do it.  In Silverlight 3 you have access to PagedCollectionView (add a reference to System.Windows.Data to get it).  This is a view that enables you to add sort and group descriptors.  In my initial loading code I instantiate a new PagedCollectionView passing in my List<Person> as the enumerable type.  I then set a default grouping on it.

   1: PagedCollectionView pcv = null;
   2:  
   3: public MainPage()
   4: {
   5:     InitializeComponent();
   6:     Loaded += new RoutedEventHandler(MainPage_Loaded);
   7: }
   8:  
   9: void MainPage_Loaded(object sender, RoutedEventArgs e)
  10: {
  11:     pcv = new PagedCollectionView(People.GetPeople());
  12:     pcv.GroupDescriptions.Add(new PropertyGroupDescription("AgeGroup"));
  13:  
  14:     PeopleList.ItemsSource = pcv;
  15: }

Then I can wire up a quick and dirty (just for demonstration purposes) ComboBox to show changing the grouping (or perhaps adding another one if you’d like):

   1: private void GroupNames_SelectionChanged(object sender, SelectionChangedEventArgs e)
   2: {
   3:     if (pcv != null)
   4:     {
   5:         // comment this next line out to see
   6:         // adding additional groupings.
   7:         pcv.GroupDescriptions.Clear();
   8:         ComboBoxItem itm = (ComboBoxItem)GroupNames.SelectedItem;
   9:         pcv.GroupDescriptions.Add(new PropertyGroupDescription(itm.Content.ToString()));
  10:     }
  11: }

You see we are just changing the PagedCollectionView and not the DataGrid.  The binding that exists between them already understands what to do – so we just have to change the data source, not the control displaying the source.  Put them all together and the running application shows the grouping:

DataGrid grouping sample image

Hopefully this helps clarify the change from SL3 beta and apologies for the delay in updating what is a common sample request.  Who knows, maybe in future versions the declarative model will come back :-).  Here’s the code for the above if you’d like to see it: DataGridGroupingUpdated.zip

| Comments

Standard caveats apply: I’m a Microsoft employee and fanboy.  I’m not ashamed.  I will say though when the announcements of the Microsoft retail brick-and-mortar stores opening, I was skeptical…no doubtful.  I kept (and still do a bit) thinking to myself how are they going to compete with the likes of Best Buy and others?!  Nonetheless, I waited patiently to see the plans.

I wouldn’t have to wait long as the first store opened up in Scottsdale, Arizona, USA.  Scottsdale is a neighboring town in the sprawl we call “Phoenix” (it’s about 40 mins from me in the QC).  When opening day came around, surely nobody would be there right?  Wrong.  Call them fanboys, eager folks to get tickets to the concert that night for their kids, whatever…but there were folks camped out.  And the lines were amazing.  The opening was an amazement to me of buzz and excitement from what I could tell.  4 days later I took the chance to go out there and take a look.

Microsoft Store EntranceI first saw a front entrance that didn’t display ‘old school’ Microsoft.  A subtle logo twist on the Windows logo (perhaps too subtle?  will people know) greets the header of the entry way.  Yes, it feels very Apple store-ish.  Naysayers flame away: copycat, blah blah.  So what…if you want to be successful, do you ignore what already has been successful?! No.

The store from the outside is very bright and clean.  Other than what are perhaps load-bearing pillars, floor-to-ceiling glass is in the entire front entry way.  When you walk in you’re greeted by some newly christened Softies (yes, they are full Microsoft employees…I see them in the GAL).  Each employee is wearing different colored shirts.  I’m assuming red means some type of supervisor or senior person.  I saw the manager, Cheryl, whom I’d been debriefed on earlier in the year.  The store was packed and I didn’t think it’d be appropriate to chat her up (aside from the fact my kids were yanking down all the Zune HDs from their docks).

Microsoft Store Crowd

I was approached by an associate who asked if I needed anything.  I identified myself as a fellow Microsoft employee and he asked me what team.  Silverlight, I told him.  Immediately he knew what that was and replied that he’s learning it right now coming from the Flash world as an animator.  Wow.  A retail clerk knowing Silverlight?!  We chatted about he Zune HD as I’d not seen them yet (one locked up on me while playing with it, which was weird). 

Microsoft Store laptop sales (dell adamo)I wandered around and was amazed at the laptop availability from all the major players: Dell (man that Adamo is sweet), Toshiba, HP, Sony, Acer, Lenovo, etc.  And all form factors: huge touch screens to netbooks.  I’m not sure how well they are priced, but the 13” Adamo was listed there at $1400.  Based on the sales figures I heard from one employee on the first day laptop sales, they were clipping along really well – people are actually buying stuff there!  I couldn’t tell for sure, but it looked like the machines purchased in the store were decrapified.  At least on the Dell’s I messed around with, the typical crapware was not installed – could have been a demo station thing, not sure and I didn’t ask.  The presentation of the machines and Windows 7 was well done though.

What amazed me was the conversations being had.  I heard more times from customers Oh, I didn’t know that.  The employees I saw engaging weren’t stumped.  These were very well prepared employees from what I could tell, accurate in information and confident in their replies to customers.  Solid.

Microsoft Store SurfaceSurface was a clear hit in the store.  There were four of them that I could tell, two “standard” ones that you see everywhere and 2 that were encased in a nicer presentation and at chest/bar level.  Perhaps this was so that adults could actually get a use on them.  The two others had a constant flux of kids in them playing the games (they were loaded up with all the demos in the world).  Seeing people interact with Surface was pretty cool – very little instruction needed other than “it’s a touch machine” – and people seemed to find it very intuitive.

There was also an “answer bar” in the back.  Yes, mock if you will the familiarity with the Apple genius bar.  Who cares, it’s the right thing to do.  There was a screen showing the appointments upcoming and it was pretty active.  I even saw someone bring in their XBOX for the red-rings-of-death fix.  Heck that alone could make the stores valuable :-).  Most people were there to understand Windows XP upgrades to Windows 7 it looked like to me.  Behind the answer bar there was also a room dedicated to instruction. 

Microsoft Store learning Microsoft Store Answer Bar

A huge screen with seating so regularly scheduled classes could be given to anyone who wishes.  For the Scottsdale store, you can find the upcoming lists on the web site for the Microsoft Store.  They have things ranging from exploring Windows 7, to getting in depth with Zune and understanding Office better.  I think this will be an essential asset for the store and Microsoft and the stores should be marketing the heck out of these learning sessions.  Everywhere.

Some cool facts?  Tons of WPF applications :-).  The wall that surrounds the entire store (which is very cool and really makes the store) is a WPF application.  One of the developers reached out to me a while back to let me know about it.  It’s pretty cool.  Also is some of the product choice helper application kiosk that are in some places (touch based of course).

Microsoft Store wall

Overall, a great experience and changed my mind.  The staff is well trained, the products are presented well and people are entering in the store.  I thought Scottsdale was an odd place for the store (it is in between a Tiffany & Co. and a Barneys) given the (yes I’m stereotyping) typical Scottsdale Fashion Square crowd.  We’ll see if that crowd levels continue through the holidays. 

The one thing that I think they are missing out on for geeks is a better name for their free WiFi.  I love how Apple brands their WiFi essentially.  Microsoft’s? RETAILGUEST.  Now anyone who has been to a Microsoft conference before will know that’s typical IT naming for us, but it misses a simple, subtle brand opportunity.  How about Microsoft Store?!?!

I think the store opening so far has been a success in sales and perception.  To me, the perception is key.  Having so many people having aha moments in the store should certainly help change their knowledge of Microsoft products and dispel some myths being portrayed.  The engaging, friendly and knowledgeable staff will only help things.  I wish that I’d seen a living room setup so that Media Center/XBOX had a better showing.  I think that is one product that isn’t out there in the consumer space enough.  And since I’ve moved completely to Media Center for my TV, having a setup showing things like the HD HomeRun and Windows Media Center with XBOX as an extender could go a long way I think.  It was energizing to see the store and how it was doing.  I wish it the best of luck!  The Mission Viejo store will be opening this week (29-Oct).

Oh yeah, and not a single BSOD in the the entire store :-).


This work is licensed under a Creative Commons Attribution By license.

| Comments

As a follow-up to my Silverlight For WordPress plugin, I have just deployed Mark Heath’s Silverlight Audio Player as a WordPress plugin.  Thanks to Mark for changing his license to Ms-PL so that I could make this happen.  If you are a WordPress user and want to use Silverlight for audio playback, you use some WordPress macro language (in this case slaudio) and put it in.  The rendered output is like this:

Silverlight Audio Player for WordPress (collapsed)

And when you click the play button it expands:

Silverlight Audio Player for WordPress (expanded)

Again, most of the actual Silverlight work is Mark’s, so be sure to head on over to his project to thank him or if you find issues in the Silverlight player.  I’ll update the plugin whenever a new version of the player is released.

NOTE: A lot of people ask me if I’m running WordPress on this blog because of these plugins.  The answer is no.  I run the most awesome Subtext framework here.  I do have a few other sites that I use WordPress on.

To install in WordPress, simply search for the plugin in your admin dashboard under ‘silverlight’ and you will find it listed as Silverlight Audio Player for WordPress.  I’ve tested it on 2.8.5 but should work back to 2.2.x.

Hope this helps!

| Comments

Previously I made note of things about the release of Visual Studio 2010 beta 2 with regard to Silverlight development.  I’ve gotten a few questions about if people should start using it for Silverlight development.  Perhaps I can help provide you with the best information I can to make that decision…so here it goes.

Go-live support

Visual Studio 2010 and .NET Framework 4 both have “go-live” support as indicated in the license terms (which are available on the VS2010 download).  If you have never bothered yourself with previous go-live products at Microsoft you may not understand what that means.

In short, “go-live” means we grant permission for you to use the product (in this case tools and framework) in a production environment.  It also means that it is a supported product at that point as well.  For Visual Studio, if you plan on using Visual Studio 2010 for go-live use, email [email protected] so you will be sure to get access to that support.  You should also read the go-live license terms clearly and back-up your project data before upgrading.  More information about go-live support can be found at Jeff Beehler’s blog post.

As with any software, pre-release or not, you should be aware of caveats and gotchas.  I’ve found a few that you should be a ware of and am listing them below.

Installer errors if you have Silverlight RTW (40624) on your machine

If you are a developer and have already downloaded Silverlight 3 when it released, you probably have installed the Silverlight Tools for Visual Studio 2008 already.  Now, if you never updated your tools to the later GDR (service packs) release, then you will encounter an error when installing VS2010 beta 2.  This is because the most recent Silverlight 3 release (3.040818) SDK does not install on top of the initial release (3.040624) SDK.  We know this and this should be remedied by VS2010 official release.

In the short-term, you need to perform a manual step to accommodate.  You can do one of two things:

  • Upgrade your Silverlight Tools for Visual Studio 2008 to the latest SDK and developer runtime.
  • Uninstall the Silverlight 3 SDK and developer runtime.

The second is probably the easiest if you’ve already downloaded the Visual Studio 2010 beta 2 bits.  Simply go to the Add/Remove Control Panel applet in Windows and remove the listings of Microsoft Silverlight 3 and Microsoft Silverlight 3 SDK.  Then run the Visual Studio 2010 beta 2 installer.

What about Expression Blend?

Here is one thing that will be a gotcha.  If you choose the Edit in Expression Blend action while in VS2010, and have Blend 3 installed, you will see that Blend will start but with this message:

Blend Warning 1

Despite what the message says, when you decide to go ahead and open the unsupported project file you will be greeted with:

Blend Warning 2

So there would be your first major caveat.  Your VS2010 project files wouldn’t be able to be opened by Expression Blend 3.  Now, I say this with caution because I’ve had some BASIC projects that have, and others that have not.  Essentially it isn’t ‘supported’ but this will be one of those areas where your mileage may vary.  This may cause you some slight discomfort when needing to tweak visual states or animations, among other things you may use Blend for (resource design, etc.).

Can it co-exist with Visual Studio 2008?

Yes, Visual Studio 2010 beta 2 can be installed side-by-side with Visual Studio 2008 SP1.  This is how I’m running it now and they isolate well.

What about my VS2008 Silverlight project files?

If you open an existing VS2008 Silverlight project/solution, VS2010 will prompt you to upgrade the project file.  Note that when you do so, VS2008 can no longer access that project file.  So this means that you can’t have VS2008 and VS2010 working on the same project/solution files for your Silverlight projects.

This can be a bit of a snag in larger team developments where you have eager developers to want to get started on VS2010, but some still using VS2008 on the same project.  Take caution here.  You can try some of the same methods used in VS2005/2008 days in creating separate project/solution files for the products, but it’s a risky move if the project properties aren’t right.

So what about Silverlight 2 development?

You mean Sivlerlight ‘classic’? :-)  Visual Studio 2010 does not support Silverlight 2 development.  Yes I know in a previous post I showed multi-targeting with Silverlight 2 and 3.  As it stands now though SL2 will not be a target for VS2010 development.

At this point any Silverlight 2 installed client should have been upgraded to Silverlight 3 if they were enabled for auto-update.  Silverlight 3 provides so many more improvements over Silverlight 2 that you should really encourage moving even existing applications to the latest runtime to take advantage of some features.

So can I use it for Silverlight 3 development then?

Works on my machine logoGiven the above known’s (and in general, the known issues with VS2010 beta 2 which are documented in the readme), yes you can use VS2010 beta 2 for Silverlight 3 development.  As noted in my previous post, .NET RIA Services is not yet supported in VS2010).  Again, the above issues might prevent you in your particular project, but I can say that VS2010 works well with Silverlight 3 development. 

Of course your mileage may vary depending on the types of projects, dependencies, frameworks, etc.  But I can confidently say “works on my machine.” :-)

Hope this helps.

| Comments

One of the cool things I came across the in the October 2009 Silverlight Toolkit release was the addition of drag-n-drop targets for some of the core controls.  Now I know you are thinking great, another drag-n-drop useless control?!? and you’d be wrong.  I’m talking about things that make it easy to do do things like moving items from one list box to another, without writing code, but with it actually doing what you expect.

Let’s take the simplest example here: ListBox and moving items from one to another.  Using Expression Blend I’ve set up my XAML to be like this:

   1: <StackPanel Orientation="Horizontal" Margin="10">
   2:     <ListBox Width="200" Height="500" x:Name="FromBox" DisplayMemberPath="FullName"/>
   3:     <ListBox Width="200" Height="500" x:Name="ToBox" DisplayMemberPath="FullName"/>
   4: </StackPanel>

Behind the scenes I have a simple class which returns an ObservableCollection<Person> and binds the results to my FromBox.  Here’s the full simple class:

   1: using System.Collections.ObjectModel;
   2:  
   3: namespace SilverlightApplication105
   4: {
   5:     public class People
   6:     {
   7:         public static ObservableCollection<Person> GetListOfPeople()
   8:         {
   9:             ObservableCollection<Person> ppl = new ObservableCollection<Person>();
  10:             for (int i = 0; i < 15; i++)
  11:             {
  12:                 Person p = new Person() { Firstname = "First " + i.ToString(), Lastname = "Last " + i.ToString() };
  13:                 ppl.Add(p);
  14:             }
  15:             return ppl;
  16:         }
  17:     }
  18:  
  19:     public class Person
  20:     {
  21:         public string Firstname { get; set; }
  22:         public string Lastname { get; set; }
  23:         public string FullName
  24:         {
  25:             get
  26:             {
  27:                 return string.Concat(Firstname, " ", Lastname);
  28:             }
  29:         }
  30:     }
  31: }

And the code for my MainPage.xaml.cs:

   1: using System.Windows;
   2: using System.Windows.Controls;
   3:  
   4: namespace SilverlightApplication105
   5: {
   6:     public partial class MainPage : UserControl
   7:     {
   8:         public MainPage()
   9:         {
  10:             InitializeComponent();
  11:             Loaded += new RoutedEventHandler(MainPage_Loaded);
  12:         }
  13:  
  14:         void MainPage_Loaded(object sender, RoutedEventArgs e)
  15:         {
  16:             FromBox.ItemsSource = People.GetListOfPeople();
  17:         }
  18:     }
  19: }

Now I want to be able to drag an item from my FromBox to my ToBox.  I could do this in code, managing my index and moving things around, etc.  Or I can use something new from the toolkit!  Adding a reference in my Silverlight application to System.Windows.Controls.Toolkit, I then add two namespace declaration in my MainPage.xaml – here’s what the full XAML looks like now:

   1: <UserControl x:Class="SilverlightApplication105.MainPage"
   2:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   3:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   4:     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
   5:     mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
   6:     xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
   7:     xmlns:mswindows="clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit">
   8:     <Grid x:Name="LayoutRoot">
   9:         <StackPanel Orientation="Horizontal" Margin="10">
  10:             <ListBox Width="200" Height="500" x:Name="FromBox" DisplayMemberPath="FullName"/>
  11:             <ListBox Width="200" Height="500" x:Name="ToBox" DisplayMemberPath="FullName"/>
  12:         </StackPanel>
  13:     </Grid>
  14: </UserControl>

Notice the xmlns:toolkit and xmlns:mswindows in the declarations.  Now I simply wrap the ListBox controls inside a ListBoxDropTarget control:

   1: <StackPanel Orientation="Horizontal" Margin="10">
   2:     <toolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True">
   3:         <ListBox Width="200" Height="500" x:Name="FromBox" DisplayMemberPath="FullName"/>
   4:     </toolkit:ListBoxDragDropTarget>
   5:     <toolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True">
   6:         <ListBox Width="200" Height="500" x:Name="ToBox" DisplayMemberPath="FullName"/>
   7:     </toolkit:ListBoxDragDropTarget>
   8: </StackPanel>

And when I run the application I get drag-n-drop item functionality from one list to the other, complete with a semi-opaque decorator as I drag the item:

ListBoxDragDropTarget image sample

Cool.  As I drag one item, it moves to the other.  But this can do more.  What if I just wanted to re-order items within a single ListBox?  This can do it as well…after all the ListBox can be both a drag *and* drop target.  However this ListBoxDragDropTarget doesn’t work with virtualized panels (which the ListBox uses by default.  So to do this you’d have to alter your ListBox ItemsPanelTemplate to include a regular StackPanel like so:

   1: <toolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True">
   2:     <ListBox Width="200" Height="500" x:Name="FromBox" DisplayMemberPath="FullName">
   3:         <ListBox.ItemsPanel>
   4:             <ItemsPanelTemplate>
   5:                 <StackPanel/>
   6:             </ItemsPanelTemplate>
   7:         </ListBox.ItemsPanel>
   8:     </ListBox>
   9: </toolkit:ListBoxDragDropTarget>

And then you’d be able to reorder using the drag/drop behavior of your mouse:

reorder sample image

Very cool.  What’s great about this is that while I’m using simple text, you can use whatever DataTemplate you may have in your ListBox and the same functionality works…even if I added an image to my Person class and added that to the template, the functionality still works and looks great for the user:

complex template sample image

As you can see the template follows the drop.  And the drop target location doesn’t have to match the same data template!  I can have my binding in the FromBox be a complex data template, but in the ToBox only choose to bind to a single property of the class.  Nice.  Here’s an animated view of this working or click here for a live sample:

This isn’t just for ListBox elements either.  Here are the other implementations:

  • ListBoxDragDropTarget
  • TreeViewDragDropTarget
  • DataGridDragDropTarget
  • DataPointSeriesDragDropTarget

Check out Jafar’s post for some samples on the other implementations to see how helpful they can be.

So what do you think?  Good?  Hope this helps some of your scenarios with ease.  Go Toolkit!

UPDATE: Download my project I used above here.


This work is licensed under a Creative Commons Attribution By license.