In Silverlight there is no Enum.Getvalue() method, so there is not out-of-the box way of databinding a radio buttongroup to an enumerable value in a viewmodel. Step forward converters. using System;using System.Windows.Data;namespace YourNamespace{ public class EnumBoolConverter : IValueConverter{ #region Methods public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){ if (value == null ||... Continue Reading →
Walking the XAML VisualTree to find a parent of type
To find a parent item of type T, you can use the following helper class: This can then be utilised as follows: Grid item = ((DependencyObject)childObject).FindParentOfType(); This was particularly useful when wanting to locate an invalid control from a ValidationSummary in silverlight, that was nested in an accordian panel: BIG shout out goes to Jedi... Continue Reading →
Silverlight PRISM Commands – TextChanged
Out of the box the Patterns and Practices PRISM code only supports the click event handler. Writing additional handlers really is very easy. Firstly there are two great starter blogs which I’m not going to recreate: How Commanding Works in Prism and MVVM by Erik Mork and A code snippet to quickly write Prism commands... Continue Reading →
Silverlight 2: Nested user controls, data-binding and property change notification.
The Problem: The parent form is in charge. This form has a view-model which has all the relevant information loaded, know which other views have been implemented, what data those view need and how and when to display and update those views. This is the master page. Within that page you can add user controls.... Continue Reading →
Silverlight 3, Validation, MVVM, WCF and EF
All the current articles and tutorials on Silverlight 3 Validation show really simplistic examples, business objects in the UI space, no services etc etc My Problem When the business objects are being created and managed via the entity framework, there does not appear to be any simple ways of adding the validation properties to the... Continue Reading →
Silverlight MVVM and Testing
During my investigations into this crazy land I have found a few good articles (and many not so good…): http://www.cauldwell.net/patrick/blog/MVVMAndTestingSilverlight.aspx http://silverlight.net/blogs/justinangel/archive/2009/02/25/silverlight-unit-testing-rhinomocks-unity-and-resharper.aspx Both use MVVM and both use RhinoMocks, but in subtly different ways.
Silverlight unit testing requirements
When setting up a Silverlight Unit Testing class the following using statements and inheritance must be applied: These are required for the TestPanel and EnqueueX methods (particularly inheritance). For more on the Inner Class Pattern, take a look at the Type Mock training blog.
Silverlight Unit Testing and Mocking
Excellent step by step post from Justin Angel – what a guy!! http://silverlight.net/blogs/justinangel/archive/2009/02/25/silverlight-unit-testing-rhinomocks-unity-and-resharper.aspx
Asynchronous Lambda Method calls
You won’t get any benefit using this code, but it makes for more manageable source. So from Pete Browns blog: All network calls in Silverlight are asynchronous. The proliferation of event handling functions this can cause just makes for really cluttered code. Using lambda expressions seems to make my code a bit cleaner. (You can... Continue Reading →
Persisted Properties
Back in classic ASP.NET I’d persist data extract from a web service in base class property as follows: private string m_stringData; public string _stringData { get { if (m_stringData==null) { //fetch data from my web service m_stringData = ws.FetchData() } return m_stringData; } } This way I could always simple use _stringData and know that... Continue Reading →