After Working at Microsoft for Four Months

December 30, 2008

Wow, time has sure gone by fast.  After four awesome months working at Microsoft, I can say, “life is great here in Redmond.”

Most of you know, I’ve never worked for a large organization before.  It was actually something in the back of my mind when making the decision to accept a position here.  Would I fit in?  Would I get lost in the shuffle?  Would my contribution matter?

I can say without any doubt that I feel like part of the family here at Microsoft and on the Cider Team.  The Microsoft culture I’ve experienced is one that energizes, encourages and enables employees to reach their full potential. 

The diversity of backgrounds, cultures, challenges and ideas provides a healthy work environment where each employee matters, can contribute to our products and services and grow professionally.

The Cider Team members and team leadership is the best group of people I’ve ever worked with.  I feel blessed that I was asked to join this fine team.

Karl, this sounds like an infomercial for Microsoft.  Nope, just serving up the straight scoop.

We work hard; have very passionate discussions about our products; our past and future decisions and the features we bring to customers.  I’ve always said, “when iron sharpens iron, sparks fly.” 

Our culture enables and encourages a process of open, sometimes critical exchange of ideas that ultimately results in a proper balance of features, stability, resources and meets customer needs.

Where Are We

I hope that each reader feels the same about their company, workplace and their fine coworkers.  Remember, many times things are what “we” make them.

In this very fast paced and uncertain economic times we live in, we don’t have time for nonsense, apathy and waste.  We need to strive to stay competitive, innovative and be motivated while delivering products and services to our customers.

I look forward to the new year with great anticipation.  The opportunities the IT industry has to offer.  The ground-breaking software that will be written.  The high school student that will learn to program because they have a computer and the thirst to learn.  It’s your time, go for it. 

I hope that you have a wonderful and safe New Year.

Have a great day.

Just a grain of sand on the worlds beaches.


Updated: Input Validation – UI Exceptions & Model Validation Errors

December 29, 2008

I have completely rewritten the Input Validation – UI Exceptions & Model Validation Errors example code and post.

While in NY City with my great friend and MVVM Master Josh Smith we spoke a lot about the MVVM layers and when it is appropriate to put code in the View code behind file.

Since the Validation.ErrorEvent is a UI RoutedEvent it makes sense to handle this event in the View code behind and for this code to call directly to the ViewModel.

The resulting code is much simpler.  I had also added a Sequence Diagram to make understanding the data binding pipeline easier when a UI Control attempts to set a value on the Model it’s bound to and their is a type mismatch.

I hope you like and can learn more about WPF  and MVVM from this article and sample code.

Have a great day!

Just a grain of sand on the worlds beaches.


Exploring a Model-View-ViewModel Application; WPF Password Manager, Cipher Text

December 29, 2008

ciphertext

I have posted an article on Code Project, Exploring a Model-View-ViewModel Application; WPF Password Manager, Cipher Text which explores some MVVM scenarios in the Cipher Text application presented in the article.

Cipher Text Application Features

  • Data stored in encrypted file
  • Flexible password generator
  • Instant full text search feature
  • Nine pre-established data entry forms (can be modified at run-time)
  • Run-time modification of a record’s shape and field behavior (add, change and remove fields)
  • Run-time configurable case correction rules
  • Dynamic and rich field validation based on assigned field behavior
  • Single click copy of any data to the clipboard
  • Nice WPF UI
  • “How To” usage video for getting the most of Cipher Text
  • Single file XCOPY deployment

MVVM Scenarios Covered

  • List of Commands Scenario
  • Showing and Hiding Views and Focus Setting Scenario
  • Data Driven Dynamic Form Scenario

I hope you like and can learn more about WPF  and MVVM from this article and sample code.

Have a great day!

Just a grain of sand on the worlds beaches.


Internationalized Wizard in WPF using M-V-VM

December 17, 2008

My great friend and Microsoft MVP Josh Smith and I spent a weekend together in December 2008, Pair Programming in New York City.  While there we wrote a cool WPF Wizard that leverages MVVM and is localized in four languages.

We have posted a Code Project article here: http://www.codeproject.com/KB/WPF/InternationalizedWizard.aspx

The source code is in VB.NET and C#.

This application demonstrates the power and simplicity of writing a MVVM application.  As you go through the code and step through the application, you’ll see how we only change data.  When data is changed, the UI that is bound to this data, responds to this data change.  This is the key to MVVM and what makes unit testing MVVM applications so easy.

I hope you like and can learn more about WPF  and MVVM from this article and sample code.

Have a great day!

Just a grain of sand on the worlds beaches.


WPF Sample Series – Using WPF Binding StringFormat Property with Nullable Types

December 16, 2008

One of the great features introduced in .NET 3.5 Framework Service Pack 1 is the BindingBase StringFormat property.  When used in a data binding expression the StringFormat property replaces most IValuteConverters that were used for formatting of values in  WPF 3.0 & WPF 3.5 applications.

Here are two examples of the StringFormat property in action formatting a currency field:

<TextBox Text="{Binding Path=Salary, StringFormat=c}" />

<TextBox Text="{Binding Path=Salary, StringFormat=\{0:c\}}" />

Nullable Type in the Mix

If you are binding to a non-Nullable data type the above will work just fine.

However, if you are binding to a Nullable data type the above will not work.

This breaks down when a UI Control like a TextBox as a value and the user clears the TextBox and press TAB.  The default implementation of StringFormat will attempt to set the Target Property to an empty string which in the the case of a Nullable Decimal property will cause the following or similar data binding exception.  The below data binding exception can be viewed in the Visual Studio Output window.

Exception

System.Windows.Data Error: 7 : ConvertBack cannot convert value ” (type ‘String’). BindingExpression:Path=Age; DataItem=’Customer’ (HashCode=31884011); target element is ‘TextBox’ (Name=”); target property is ‘Text’ (type ‘String’) FormatException:’System.FormatException: Input string was not in a correct format.

at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)

at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)

at System.String.System.IConvertible.ToInt32(IFormatProvider provider)

at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)

at MS.Internal.Data.SystemConvertConverter.ConvertBack(Object o, Type type, Object parameter, CultureInfo culture)

at System.Windows.Data.BindingExpression.ConvertBackHelper(IValueConverter converter, Object value, Type sourceType, Object parameter, CultureInfo culture)’

TargetNullVaue to the Rescue

In the above example, the exception is thrown because of a type mismatch.  In WPF 3.0 and 3.5 I had a set of Nullable ValueConverters for my applications to handle this problem.

Another great feature introduced in .NET 3.5 Framework Service Pack 1 is the BindingBase TargetNullValue property.  This property can be used to handled the type mismatch problem when converting an empty string from a TextBox to Nothing (null) when the binding pipeline sets the target Nullable property.

Let’s have a look at the two below TextBoxes.

<TextBox
    Grid.Column="1"
    Grid.Row="1"
    Margin="0,11,11,11"
    VerticalAlignment="Top"
    Text="{Binding Path=NumberOfComputers,
            TargetNullValue={x:Static sys:String.Empty},
            StringFormat=\{0:D\}}" />

<TextBox
    Grid.Column="1"
    Grid.Row="2"
    Margin="0,11,11,11"
    VerticalAlignment="Top"
    Text="{Binding Path=Age, StringFormat=\{0:D\}}" />

These TextBoxes are both bound to Nullable properties.  The first TextBox takes advantage of the TargetNullValue property and works as expected.  The second does not.   The data binding pipeline will throw an exception when the second TextBox is changed to an empty string and it attempts to assign the value of String.Empty to the Target property.

Here is a potential problem.  If the exception gets thrown and swallowed because the code didn’t check for this, the user thinks they cleared a value but the property the TextBox is bound to never gets changed due to the exception being thrown.

Download

I’ve included a very simple project that you can download a play with.

After downloading the project, please change the extension from .doc to .zip.  This is a requirement of WordPress.com.

Download Sample Project (25KB)

Steps To Reproduce Issue

Launch included program using debug mode.

Ensure Visual Studio Output window is visible.

Set each TextBox to 7.

Go to first TextBox.  Clear field and press TAB.  Notice nothing is added to the Output window.

Go to second TextBox.  Clear field and press TAB.  Notice nothing an exception is added to the Output window.

Close

When binding to Nullable types, use the TargetNullValue property along with the StringFormat property to avoid type mismatch exceptions.

Hope this tip has helped you learn more about WPF!

Have a great day!

Just a grain of sand on the worlds beaches.


WPF Toolkit DatePicker Memory Leak Problem

December 16, 2008

Back on 8 December 2008 I had blogged about memory leaks and that I narrowed the leak down to a control. 

The WPF Toolkit DatePicker control has a dependency on the WPF Toolkit VisualStateManager.  The VisualStateManager has a memory leak that gets surfaced when using the DatePicker control.

Microsoft does not recommend shipping the DatePicker control to customers.

The Microsoft public announcement can be read here in this CodePlex VSM/DatePicker Known Issue post.

Hope you have a great day!

Just a grain of sand on the worlds beaches.


WPF M-V-VM Series Begins

December 11, 2008

Sorry it has taken so long to being posting to this series, but trust me the wait will be worth it.

I would like to thank Jaime Rodriguez and Josh Smith for working together with me and you’ll be seeing more information begin to flow from them.

I have set up a WPF & Silverlight Line of Business UI Design Pattern Home Page that will contain all articles, references and links to M-V-VM on my blog.

I have added my first article to the home page entitled, “Input Validation – UI Exceptions & Model Validation Errors.”  There is a link towards the bottom of the M-V-VM Home Page.

Please read the very short Home Page first so that you’ll fully understand the series content and direction.

This first article is out of order, normally a blogger would do the big introduction article first, but since this has taken longer than I wanted, I’m providing some meat up front and will go back and write the M-V-VM Introduction soon.

Also, look for a new version of XAML Power Toys, Code Name: M-V-VM that will assist in creating M-V-VM Views and ViewModels.

Hope you have a great day!

Just a grain of sand on the worlds beaches.