Items collection must be empty before using ItemsSource

In silverlight or WPF if you get the error:

"Items collection must be empty before using ItemsSource"

make sure you aren't populating the control with both the ItemsSource and adding children to the control in XAML.  In my case, I was setting ItemsSource after a call to a WCF service.  I had mistakingly also added a placeholder object in my XAML until I had written the WCF call.  Oops. 

Hope this helps somebody,

Scott

Tags:

Silverlight

VS 2010 RC problem with missing ObservableCollection for WCF services

I'm back into Silverlight 3 now after a long break.  Since VS2010 RC was just released, I decided to upgrade my existing SL3 project and enjoy the benefits of a greatly improved IDE.  The project appeared to convert to just fine, but I had compile errors.  It seems my ObservableCollections were now arrays.  When attempting to update/configure a service reference, it chooses ( Custom ) and ObservableCollection is no longer a choice!

Somebody goofed at Microsoft and left out the ObservableCollection type.  To fix, you need to do this:

1.  Choose System.Collections.ObjectModel.Collection as the Collection type (instead of ( Custom )).

2.  Update, or configure your reference

3.  Find the reference.cs (or .vb) file (open windows explorer and find it in your Services References folder)

4.  Change all System.Collections.ObjectModel.Collection to System.Collections.ObjectModel.ObservableCollection.

 

Back in business.  I have no doubt they'll fix this by RTM, but that allows me to work with the RC and Silverlight/WCF.

I hope this helps somebody.  Happy programming.

 

Tags: , ,

Silverlight

Blog Spam

I hate blog spam.  I have been getting a lot of it.  I am upgrading to BlogEngine.NET 1.6 and we'll see if that takes care of it.

Tags:

finally fixed my email

For anybody who tried to contact me via my blog, I haven't gotten any messages. I just discovered I had a bad smtp server.  OOPS!

Tags:

SourceSafe on it's way out!

I haven't used VSS since 2007, but good to see an "end of life" plan being developed to finally get developers off it.  The problem I've seen before is that TFS just plain costs too much.  This drives people to other solutions like Subversion and Git

http://tech.yahoo.com/news/infoworld/20090930/tc_infoworld/93983_1

Tags:

General

Product cross sells using Linq to SQL

Ok, so finally I have an e-commerce related post.  Tonight I was adding cross-sells to my site.  The concept is simple - when displaying a product, at the bottom of the product page, list products that might also be of interest to the shopper.  To facilitate this, you'll need a Cross Sell table:

This table just contains two product id's.  One is the product Id of the item the shopper is currently viewing, the other is the product Id of the product that you want to cross sell.  So all you have to do is make a call out to your database by passing your product Id and return one or more products that you want to cross sell.  Then display them.

In the past, I would have written a stored procedure to retrieve the data.  Something like this: 

But I'm moving away from stored procs in this new e-commerce site I'm working on, and using Linq to Sql.  I have written hundreds on basic linq queries, but how do you accomplish this task?  I have a select embedded inside a select.  Well, here is the solution:

First grab your Cross Sell records and store them in a var called crossSells.  Then create another query from your Products table, join to manufacturers (to get the manuf. name for dispay purposes), and set the where to get those items from crossSells that contain your productId.  No matter how many "queries" you construct, only one SQL statement is executed.   Your var is an IQueryable and you can embed these inside others.  Very cool and very easy to get straight in your head when you seperate them. 

 

 

Your SQL query isn't actually constructed and run until you enumerate over it (call .ToList() for example).  In the above code, I want to return a generic list of Product objects. So, after creating my two linq statements, I return products.ToList();

The SQL that is created can be easily seen.  Just set a breakpoint on the return statement and look products. 

There you have it.  Move away from stored procedures and into the cool world on Linq to SQL (or Linq to Entities).

Thanks to Rob Conery's blog for this information.

Tags:

e-commerce

Making table changes in SQL Server 2008

This is more of a note to myself.  Every time I reinstall SQL 2008 and want to make a table change, I am faced with this error: 

Nice warning, but please, just let me make changes to my tables.  I'm trying to develop here.  Now I understand this is good for a production environment in case you are making a quick change to a table (I would use RedGate's tools myself though).

To fix this, in SSMS, go into the Tools menu, choose Options.  Then click on Designers in the treevier.  Uncheck "Prevent saving changes that require table re-creation".  There you have it. 

Again, I have forgotten about this setting a dozen times.  Hope it helps someone.

Tags:

Silverlight 3 Pros and Cons

great post by Dan Wahlin here on the pros and cons of SL3 developement.  I have been wanting to blog more on my experiences in e-commerce development but am struggling to find time.  I'm a one man shop at the moment!  Work on my new ASP.NET site is coming along nicely.  I have a professional UI in place now, just tidying up the paging and completing the checkout process.  Once that is finished, It's back to my SL3 administration application.  Silverlight is such a great platform and it's really going to allow my customers to efficiently manage their store. 

More blogging to come...

Tags:

e-commerce

AG_E_PARSER_BAD_PROPERTY_VALUE

Why in Silverlight 3 do I still get these cryptic error messages?  This happens quite frequently to me.  I do a lot of copy/paste between my user controls in Blend or Visual Studio.  Take a look at this XAML for a Button: 

 

<Button x:Name="btnSave" HorizontalAlignment="Right" Margin="5" Content="Save" Grid.Column="3" Grid.Row="20" Click="btnSave_Click" />

 

I just copied this from another user control onto a new user control.  It just happens to contain a handler for the Click event, "btnSave_Click".  Well if you forget to create the event handler for it in your new control, you end up with the cryptic

 

To fix, go back to your XAML, right click on this:

Click="btnSave_Click"

and choose "Navigate to Event Handler".  This will create a stub method for you and you can continue on.

Why in a V3 release are we still not helping developers along?  Yeah, I goofed by just doing a copy/paste without also creating the event handler, but why isn't VS smart enough to tell me this?

 

Tags:

Good tutorial for Silverlight with WCF and Linq To Sql

Part of Jeff Blankenburg's "31 Days of Silveright".  I went through this tutorial to get myself refreshed on Silveright.  It's been about 6 months since I've done a SL2 project and needed refreshing.

http://jeffblankenburg.com/2009/07/day-7-using-wcf-web-services-with.aspx

 

Tags: , ,