Data validation – Silverlight versus WPF part 2

In a previous blog post I pointed out that quite a difference between data validation between Silverlight and WFP. As I don’t think adding data validation in the UI is a good thing I focused on validation in the business object by throwing an exception when the value was not acceptable. As Beth pointed out WPF also supports the IDataErrorInfo interface as she demonstrates here. I think using the IDataErrorInfo interface is superior to throwing exceptions. After all exceptions should be exceptional and users entering invalid data in real applications is not very exceptional  [:(]. However Silverlight only contains a … Continue reading Data validation – Silverlight versus WPF part 2

How to know when the DataContext changed in your control

The DataContext is a wonderful property, you can set it somewhere in the logical tree and any child control can just bind to properties without having to know where the DataContext was set. A great capability that makes live much simpler when writing XAML. But sometimes when building a control of some sorts you just need to know when the DataContext has changed. For example when binding to events on whatever object is set as the current DataContext. Take for example the following simple form. In this form I am data bound to a real simple Person object which implements … Continue reading How to know when the DataContext changed in your control

Making sure asynchronous unit tests don’t cause a deadlock

In my previous blog post I wrote about creating asynchronous unit tests for Silverlight using the Microsoft Silverlight Unit Test Framework. This asynchronous testing capability that the Microsoft Silverlight Unit Test Framework has in the box lets us create some pretty advanced testing capabilities. The problem with asynchronous tests. While the async test pattern is very powerful it also has a drawback. This drawback is that the EnqueueTestComplete() must be executed or the test will never complete and the whole test run will halt. And while the test runner will tell you which test is executing it will not tell … Continue reading Making sure asynchronous unit tests don’t cause a deadlock

Unit testing in Silverlight part 3

Part 1 Part 2 Part 3 Part 4 This post continues on my previous two post on using the Microsoft Silverlight Unit Test Framework. You can find part 1 here and part 2 here. In the second blog post I showed how to create a wrapper around the WebClient class, the TestableWebClient, so we can actually test code doing asynchronous web access. The part I didn’t really explain was the unit test itself. The unit test code looked likes this: [TestClass] public class FlickrDownloadTest : SilverlightTest { [TestMethod] [Asynchronous] public void Test1() { FlickrRequest request = new FlickrRequest(typeof(MockTestableWebClient)); request.PhotoSearchByUser("97044050@N00", (photo) … Continue reading Unit testing in Silverlight part 3

Data validation – Silverlight versus WPF

When I am creating business applications validating the data in business objects, and displaying any errors, is always a big deal. Even though WPF and Silverlight both use XAML and support data binding the default way to display errors is quite different. Now I am focusing on validation in the business object here even though WPF has additional capabilities of validating input in the XAML using ValidationRules. While there might be some good reason to validate data directly in the UI in some cases I find it a requirement to validate data inside a business object so the validation is … Continue reading Data validation – Silverlight versus WPF

WrapPanel in ListBox revisited

Last week logged about using a WrapPanel in a listBox and demonstrated how to get the content to wrap around, read about it here. Turns out the XAML can be even easier. In the previous post I used a ControlTemplate with a Grid to stop the WrapPanel from just expanding horizontally. Turns out there us an even easier way to do so by disabling the horizontal scrollbar using the ListBox ScrollViewer. The following XAML will do the trick just fine: <UserControl xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls" x:Class="SilverlightApplication4.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <Grid x:Name="LayoutRoot" Background="White"> <ListBox x:Name="DemoList" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <controls:WrapPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> … Continue reading WrapPanel in ListBox revisited

Unit testing in Silverlight part 2

Part 1 Part 2 Part 3 Part 4 In my previous post I described the basic setup of unit testing in Silverlight, you can read all about it here. The basics where very nice but lots of code we write in Silverlight has to do with networking and in Silverlight that means asynchronous code, something that is always hard to test! Because, just I like using Flickr, lets download some pictures and see what it takes to make that testable. Below is the very simple application we need to unit test, basically a list of pictures from my Flickr photo … Continue reading Unit testing in Silverlight part 2

Unit testing and Windows Workflow Foundation

A while a go I wrote some posts about unit testing Windows Workflow foundation Activities, you can find the posts here and here. Fortunately I am not the only one who thinks unit testing is important as you can find various other blog posts about it like this one from Ron Jacobs. But Cliff Simpkins has taken this one step further and just blogged about a new MSDN virtual lab “Using Test-First Development with WF”! Excellent work and I recommend doing the lab, I know I did! And while you are at it, there are a  number of other interesting … Continue reading Unit testing and Windows Workflow Foundation

Unit testing in Silverlight part 1

Part 1 Part 2 Part 3 Part 4 Unit testing is an important part of daily life for a developer and with good reason. After all unit testing software makes it easier to make changes and change is the only constant in software development! With regular .NET code you can right click on a class and select “Create Unit Tests” to get started. Unfortunately with Silverlight that just shows the following empty dialog. The reason being that Silverlight source code is compiled against a different runtime and Visual Studio 2008 doesn’t know how to run those tests. Fortunately the Silverlight … Continue reading Unit testing in Silverlight part 1