Vote Telerik!

Are you a Falafel or a Telerik fan? We need you…
 
If you are a Falafel or a Telerik fan, then do us a favor. Vote for Telerik in this year’s DevProConnections Awards: http://svy.mk/nDygA2
 
We are very proud to see that our partners from Telerik have been nominated in a staggering 20 categories in this year’s DevProConnections Community Awards, a testament to how comprehensive Telerik's approach to software development solutions has become. From Visual Studio add-ins like JustCode to our CMS of choice, Sitefintiy, Telerik’s  best-of-breed solutions have helped Falafel's team deliver better software, faster.
 
Here's what ...

If you read my previous blog post Two Good Ways to Work With Excel Files in C#, you will be excited to learn that there is now an even better way! Check out the EPPlus project on CodePlex. It is based off the original ExcelPackage, but is faster and adds in tons of new features, including support for formulas, cell styling, charts, pictures, shapes and much more, a huge leap in functionality. Also, it is actively being developed, where ExcelPackage kind of died. I was able to upgrade my code with hardly any change, all I needed to ...

While working on an MVVM project, I was recently debugging an issue with some of my Silverlight ComboBoxes.  The ComboBoxes were bound to pre-set values in the ViewModel, and yet were showing up empty when rendered on the page.  What was really troubling was that some ComboBoxes were working correctly, but others were showing up blank, when they were bound to the same ViewModel and everything looked to be exactly the same!

Here’s a sample project where I’ve reproduced the problem:

Both ComboBoxes are bound to the same ItemsSource, and both have simple int values as their bound SelectedValue ...

The MVVM design pattern works extremely well in Silverlight.  A typical implementation of this pattern is to create a ViewModel for each View or Page in your application.  This gives you a clean separation between your View and ViewModel and it also provides logical separation for your ViewModels so they don’t get bloated.  For larger applications, you may find that each View has multiple ViewModels or a Page is comprised of several UserControls, each of which have their own ViewModel.  Once you get to this point, it can become challenging to communicate between the ViewModels and tie everything together in ...

Here’s another permutation of my generic attached property. This time we’re dealing with the problem that occurs when you have a TextBox that’s binded to a filter of some collection. If you do just a straight binding between the TextBox.Text property to the Filter to a CollectionViewSource, then you’ll notice that the binding does not update the filter until you shift focus away from the TextBox. You can get around this by updating the binding in the TextBox.TextChanged event like this.

 

The previous blog on Categorized Lists with LongListSelector demonstrated IGrouping implementation. If we play it right, we shouldn't have to touch the "Grouping" class to group using complex objects.

I'll use a playing card deck as a familiar data model that has categories to group on, i.e. the "Suit" that contains "Clubs", "Spades",  "Hearts" and "Diamonds" and where each card has a value from two through nine and including "Jack", "Queen", "King" and "Ace". The cards can appear in the LongListSelector with the Suit in the heading for each group and the value for each card making up the details ...

Someone recently asked me for advice on how to bind the visual state of a Silverlight control to a property of the view-model.  Specifically, they had a Boolean property on their view-model named something like IsExpanded that they wanted to control the expanding and collapsing of a control in the view with the value of this view-model property.

It was such a fun sounding challenge—and one that seemed like it would be very useful to have for many situations—that I couldn’t resist creating a simple solution. 

Here’s What I Created (Silverlight 4 Plug-In Required)

Get Microsoft Silverlight

 

Here’s How I Did It...

Quite often in my copying and pasting frenzies for Silverlight properties that use notifications I will forget to change the string inside the constructor to PropertyChangedEventArgs(string). The string is the name of the property that needs to send the property changed event. More times than not the calling property getter or setter is indeed the property that needs to be changed so I updated my RaisePropertyChanged method to look at the call stack and find the name.

 

Here’s my NotifyPropertyBase abstract class that I base all my View Models upon:

 1:  public  abstract  class NotifyPropertyBase : INotifyPropertyChanged
 2: {...

You can use LongListSelector as a glorified ListBox, but that cripples its true purpose. The real power  of LongListSelector is to display long categorized lists, enable a "People Hub" style "jump list" to navigate between groups in the list and to allow performant scrolling.

Grouping

The trick to get LongListSelector working is to properly group the data assigned to the LongListSelector ItemsSource. You can start with a simple flat list of objects, where each object has a property suitable for grouping. In the snippet below, "MyObject" has a "Category" property that the list will be grouped on....