I’ve always liked attached properties… so much so that a couple of years ago I created a series of generic classes to simplify the process of creating custom attached properties.

Attached Properties – a review:

  • External control interactions — like the Grid.Row attached property.
  • Basic info storage — just like the Tag property.
  • Behaviors — changing properties and behaviors of the parent control.
  • Bindings — to achieve custom bindings between UI controls.
  • If you use XAML, you use attached properties whether you realize it or not.

Creating a custom attached property only takes a few lines of code. Many declarative ...

Developing in XAML (Windows 8, Silverlight, Windows Phone, or WPF) gives you a powerful combination of declarative markup with databinding, but one shortcoming I often come up against is the ability to build simple ComboBox elements declaratively with both Content and Values.
If you are familiar with HTML, you know that you can use a select tag to pair the display name with a key value, such as:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value...
Every year, October kicks off a very busy season at Falafel : “Conference Season”. Multiple members of the team travel across the country and around world to share their expertise on a number of technologies. All Falafel Software team members spend their days, and often their nights, helping design and build cutting edge solutions for our customers. Their technical presentations draw from these real world experiences and are assembled, practiced, and presented in what little spare time they have. That’s why we call them “Rock Stars”.

This weekend at Silicon Valley Code Camp, Falafel’s entire team from around the ...

The Problem

I recently discovered that the default Silverlight DateTime format is different on MacOS than it is in Windows.

 

On Windows

windows

 

On MacOS

mac

 

There are a couple of differences, but the most noticeable is that time zone offset at the end of the time that shows on the Mac. On my computer the time zone offset shows as “-4:00” because I’m generating a DateTime in local time, which for me is currently Eastern Daylight Time (EDT), or 4 hours behind Coordinated Universal Time (UTC).

 

The application is following the best practice of storing all DateTimes ...

I’m a huge fan of the Microsoft Prism framework. In fact, I’ve blogged before about using its DelegateCommand to minimize your ViewModel code.

Lately, though, I noticed that once its CanExecute delegate returns false, your IsEnabled binding will not update, even when the property it’s bound to changes.


Try It Out: Live Example

Note: Silverlight 4+ Plug-in Required
Get Microsoft Silverlight

 

As you can see, the button entitled “Prism Command” starts out disabled and never enables, even though its IsEnabled property is bound to the same property of the ViewModel as the other buttons (see below).

 

<Button Content=...

The Windows Phone platform has been making headlines lately.  A Customer Think survey recently revealed that among smartphone users, Windows Phone users experience the highest customer satisfaction. Nokia's new Lumia 900 Windows Phone debuted at the Consumer Electronics Show and took home CNET's best cell phone award. Market research firms iSuppli, Gartner and IDC all expect Windows Phone to claim the number two spot in smartphone market share by 2015.


So what's the big deal?


We are giving you a chance to see for yourself. On Feb 10th at 12PM EST, join us in our free Windows Phone webinar, "The ...

There are some powerful data editing controls in Silverlight such as the DataForm which let you define templates for ReadOnly and Edit modes, but sometimes you just need a simple way to view and update text.  I came across a scenario in a custom application that required a simple way to view and edit text.  The solution I came up with was a "Click to Edit" TextBlock.  In the default state, the text is displayed as a read-only TextBlock, but you can simply click on the TextBlock for it to become an editable TextBox.

Here is a working example (Silverlight ...

When building Line-of-Business applications, we typically provide a variety of ways to search for customer or transaction data.  One of the common search types is a date range search.  Telerik provides an excellent UI control to select dates, the RadDatePicker.  

So now your application has a begin date and end date for your search and everything looks great until you realize that the end date is never included in the search results.  This is because the DatePicker control defaults to midnight on the selected day (0 hours, 0 minutes, 0 seconds, 0 milliseconds) and if you use less-than ...

When using a ComboBox or ListBox attached to a list of business objects, your list of business objects more than likely does not have an empty value object. If, for example, these business objects are from a database, the table definition might not allow null values. Changing the table to allow null can fix the problem but that might not be the best solution because it might allow invalid data to be put into the table.

A solution to this is to add a blank business object into the list in Silverlight, more specifically with a converter. We can use ...

Have you ever created a UI element in Silverlight (a Grid, Rectangle, Border, etc.) with transparent components and wondered why it was so hard to click on?  Most likely, it’s because the background or fill brush of your element is null.  Null fill and background brushes allow mouse events (and touch events for WP7 apps) to go through to whatever is behind the element in question.

Instead, you can set a fill or background brush to the pre-defined color “transparent”, and your element will now always intercept mouse and touch actions and raise the corresponding events.

Below is a simple ...

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 ...

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: {...

Today I spoke on Windows Phone 7 Application Development at the Grand Rapids Day of .NET.  We had a great group in the session.  I was very happy to see their level of interest, excitement, and great questions.  I hope that they found the session useful. 

As promised, here are the slides and code for download:

- Download Slides (PowerPoint 2007)

- Download Sample project (VS 2010)

 

I’ve also included some links below to more WP7 resources.  Feel free to contact if you have any questions.

 

Additional Reading:

- Using Push Notification from Your Windows Phone Application

- ...

I got some positive feedback on my recent post about binding a TextBlock’s tooltip to its own text property, so I decided to post this related follow-up…

 

Allowing your users to navigate your forms with the keyboard is a very important usability feature that is often overlooked.  In Silverlight, this is accomplished by setting IsTabStop to True on any controls you want to participate in keyboard navigation.  When the user hits the tab key, focus will cycle through all the controls where IsTabStop is True, one at a time.  Any controls where IsTabStop is false will be skipped....

Those that have been programming in WPF for a while probably already know about defining styles based on other styles.  With the release of version 3, this feature made the jump over to Silverlight as well.  Even though this is old news, as Silverlight is now on version 4, I’ve found that this feature is still little-know, and it’s so useful, I thought it deserved a post.  In the post, I’ll go over the basics of how to use this feature for anyone to whom the feature is new.

 

Why Use BasedOn

Using BasedOn to define a style allows ...

In every Silverlight project I have worked on I have needed to set some default styles for use throughout the Silverlight controls. So I create a new Silverlight Resource Dictonary and typically add items such as SolidColorBrush:

<SolidColorBrush x:Key="DefaultForeground" Color="#FF1F4386" />
<SolidColorBrush x:Key="DefaultLabelForeground" Color="GreenYellow" />

 

It is great to have one place to define styles and for the case above colors of my Silverlight components but then I wanted to set a particular font family and font size. This wasn’t immediately clear to me how to do that because ...

There’s not always enough room in the UI to display the entire contents of a TextBlock.  Silverlight 4 includes the a new TextTrimming feature that allows you to cut a TextBlock’s content off after the last word that fits plus an ellipsis (. . .) at the end.

When I use the new text trimming feature, I like to put the un-trimmed contents of the TextBlock into its ToolTip so that the user can still see it when they mouse over the control.

The example below shows you how you can wire a TextBlock’s ToolTip to be bound to its ...