Microsoft Certified Technology Specialist

On December 10th I got my first Microsoft certification. I’m now a Microsoft Certified Technology Specialist: .NET Framework 3.5, Windows Presentation Foundation Applications. I got 957/1,000, so I’m proud about myself. :-)

Microsoft Certified Technology Specialist

Tags: , , ,

Opening files closes VS2008

Once in a while I happen to have a project that simply closes when a file such as .resx or .xaml is opened in Visual Studio 2008 – even when there is nothing wrong with the files themselves.

When that happens, errors are logged to the Event Viewer, but they are not that helpful – for a change.

To avoid that error, there is a couple of ways. First of all, delete the .suo file in your solution folder. Deleting that file will do no harm to your solutions, as it only stores user-specific information, such as what are your opened files, which directories in Solution Explorer are collapsed or not, etc.

That usually works. However, not always, specially with .xaml files. If VS2008 insists in closing after deleting .suo, next time you open the .xaml file, simply press ESC repetitively, the way maniacs do. That will avoid the design view to be loaded – which apparently breaks VS2008. If you are successful in not seeing VS2008 to close again, you can close your file and re-open it. Hopefully.

What if Visual Studio still closes? Good luck, my friend.

Tags: , ,

String.Format() on XAML for WPF

Just found out some nice tricks on WPF, so here are some quick hints about using String.Format() with multiple parameters on XAML for WPF (and possibly Silverlight).

Say that you have a Phone class that contains three properties: CountryCode, AreaCode and Number. The DataContext for your Window contains a property of type Phone, and you want to print that object information in a pre-formatted way defined at the XAML file. The desired format is something like +1 55 55555555 (plus sign, followed by CountryCode, followed by a space, followed by AreaCode, followed by a space, followed by Number).

So instead of creating a property to hold the pre-formatted string at your class side, you just want to define it at XAML level.

Take the code below as an example:

<TextBlock>
	<TextBlock.Text>
		<MultiBinding StringFormat="+{0} {1} {2}">
			<Binding Path="Phone.CountryCode" />
			<Binding Path="Phone.AreaCode" />
			<Binding Path="Phone.Number" />
		</MultiBinding>
	</TextBlock.Text>
</TextBlock>

That will just do the trick for you!

However, we have some considerations to pay attention at. First of all:

<MultiBinding StringFormat="+{0} {1} {2}">

That line just works because of that trailing plus sign. If you were to use no plus sign (or any other prefixing string) at all and just display CountryCode directly, then you need a small tweak:

<MultiBinding StringFormat="{}{0} {1} {2}">

That’s the {} just before {0} parameter.

Furthermore, there are some nice attributes to add to the Binding element. For instance, if the value of your DataContext Phone object can’t be retrieved in design-time, you might see {DependencyProperty.UnsetValue} displayed on your design screen. TargetNullValue and FallbackValue can be added to fix that.

<TextBlock>
	<TextBlock.Text>
		<MultiBinding StringFormat="+{0} {1} {2}">
			<Binding Path="Phone.CountryCode" TargetNullValue="--" FallbackValue="??" />
			<Binding Path="Phone.AreaCode" TargetNullValue="--" FallbackValue="??" />
			<Binding Path="Phone.Number" TargetNullValue="--------" FallbackValue="????????" />
		</MultiBinding>
	</TextBlock.Text>
</TextBlock>

The first one is the substitution for null values, while the value of the second one is returned when no value can be found (such as when the bound property is not initialized in design-time). Just take care as that works on runtime as well!

Just some tricks particularly interesting during MVVM development. I hope it can be of some help!

Tags: , , , ,

Metaphor of a webdeveloper’s life

I was just listening to The Aquabats – The Baker and I guess I paid attention to the lyrics for the first time. It just tells the story of every webdeveloper and their conflict with webdesigners:

I am the Baker
I bake the cake
You’re the decorator and you decorate
You take the credit
While I slave away
I mixed, I made, I baked!

You can check the lyrics here.

Tags:

The philosophy of technical restrictions: why value comparison is not available in .NET?

Or: Unavailability of value comparison of objects in .NET, a technical or philosophical restriction?

I was working on unit tests and then a question came to me – why comparing objects by value is not provided out-of-the-box by the .NET Framework? We all (should) know that by default, comparing objects leads to a reference comparison, unless of course you override Equals() or implement operator == on your class.

But what if I want to compare two objects from a class provided by the Framework? That would be quite handy specially for unit tests. While we have System.Object.Equals() and System.Object.ReferenceEquals() working the very same way – reference comparison – we don’t find something like System.Object.ValueEquals().

Then I started having a discussion with a friend and colleague of mine the reasons for such functionality not existing in .NET.

Although I agree that the default option should be reference comparison, I don’t see any technical limitations for not having that implemented – Reflection could be the way to do it, going recursively down each property and checking if their values are equal.

So why not? Is it something related to the theory of object orientation or was it a mere technical decision?

Let’s take one of the classical examples of OO lessons: a Car class. In a Car, you have properties such as Color, Model, Category, etc. In real life, when two cars come out of production line, while you can’t say they are the same car, one would have no problem identifying they were built by the same method. Just compare each of their properties and you will end up knowing they are not the same car, but they share the same properties and were built the same way. They don’t share a reference equality, but value equality.

As far as I am concerned, OO does not provide a specific way or method to apply the property-by-property comparison, but there isn’t a prohibition on doing that as well.

However, providing such functionality could be an expensive trade-off, since gigantic objects with collections with millions of items could be compared. It would be possible, but sometimes not practical. But then not providing that for the developer’s discretion, or at least providing ways to ensure it could be safely used? Doesn’t seems right to me.

From my point of view, such functionality could be very useful and there is no true restriction that should be applied for having something like that provided by the Framework. As I said, my opinion is that not providing it is a technical decision, and not a philosophical restriction imposed by OO theory.

What do you think? I’d be glad to listen to other opinions!

Tags: , , ,