Enumeration Binding in Silverlight

by Dean 31. January 2009 10:57
A contractor colleague of mine (Phil Steel) had an interesting Silverlight problem yesterday. He wanted to populate a Silverlight ComboBox with an enumeration, and implement 2-way binding to a property on his Data class (i.e. binding his property to the ‘SelectedItem’ on the ComboBox. His requirements were as follows: The solution must have full design-time support in Expression Blend The code must give the developer an opportunity to create metadata for the enumeration that can be used for ‘user friendly’ visual values in the ComboBox There must be full 2-way binding, so no need to tap into the ‘SelectionChanged’ event to update the data object. Minimal C# code, with as much as possible being re-useable ‘as is’ for any enumeration. Ok, so I googled around and only found fragments of a possible solution, so I decided to engineer one myself. The details are below Task 1 : Create reusable code that converts a .NET enumeration into a collection   There are 2 c... [More]

Tags: , ,

WCF | Silverlight | DataBinding

Fixed - Issues With WCF and Mixed VS/Blend Development

by Dean 25. January 2009 12:37
Some of you may have come across an issue when developing ‘fast and dirty’ demo apps in Silverlight that have a WCF backend service on the web application. When developing throwaway demo apps for clients, you need to take all of the shortcuts you can get, so I always use the ‘Add service reference’ feature of Visual Studio to add a service reference within my Silverlight app to the host ASP.NET service (not advisable for production-quality apps though). This is a great feature because as you change the service interface you can keep in sync on your Silverlight app using a single service ‘Update’ button. However, the big drawback of this approach is that the Visual Studio tool that creates the service reference hard-codes the service Uri into the generated classes. If you were just using Visual Studio then this wouldn't be a problem, but unfortunately VS and Blend use different development servers that cannot co-exist on the same TCP port, so for one of the two development environmen... [More]

Tags: , ,

Silverlight | DataBinding | WCF

Silverlight and Related Blogs

by Dean 24. January 2009 14:25
I've spent some time tracking down Silverlight oriented (or related technology) blogs so I can keep on top of the community using FeedReader on my daily train journey into London. If anyone would like to add these blog references into their own RSS reader, you can download the OPML file below   Silverlight and Related Feeds (OPML File)   Please let me know if I've missed anyone, and I’ll keep this file up-to-date Dean

Tags: , ,

Silverlight

Generic IValueConverter for Silverlight or WPF

by Dean 24. January 2009 10:37
When using the GridView in ASP.NET it is very handy to be able to include a ‘FormatString’ attribute to bound columns and the like – enabling you to display those dates, currency values, numbers etc in a more readable form. I was surprised that Silverlight or WPF doesn't offer this out of the box, and I couldn't find any ‘obvious’ answers when I googled the subject, Therefore, I created a simple IValueConverter to achieve the same result. Here's the code for the converter: namespace CBSSilverlight { public class FormatStringValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) return string.Empty; return !string.IsNullOrEmpty(parameter.ToString()) ? string.Format(culture, parameter.ToString(), value) : value.ToString... [More]

Tags: , ,

DataBinding | Silverlight

ObservableCollection Base Class With Expression Blend Designer Support – An Example Project

by Dean 19. January 2009 17:31
In my previous post showed how to create a lightweight collection class that can be used in expression blend enabling design-support for data bound control development. In this post, I thought I’d expand on my previous writings and actually create a sample project from beginning to end – demonstrating how easy it is to use this solution. Step 1 – Create Your Project (Programmers Job) In VS2008, create a Silverlight application project – Im going to call mine EmployeeInfo for the purpose of this blog. I also need to create my data classes, So I’m going to create 3 My generic base collection class that provides all of the test data (CollectionBase.cs) My Domain/Business object – in this example, it’s going to be a ‘person’ object that represents employee data (Person.cs) My person-specific collection class that provides a data-binding target for Expression Blend design (PersonCollection.cs) The code for CollectionBase.cs and PersonCollection.cs is available in the... [More]

Tags: ,

Silverlight | DataBinding

ObservableCollection Base Class With Expression Blend Designer Support

by Dean 18. January 2009 23:54
One of the big issues for me with using Expression Blend for design in conjunction with VS2008 for the hard coding, is that you need to create at least test data loading stubs in the middle tier, delivered over WCF/WS in order visualize databound controls in the Silverlight app. This means that you often need to have everything ‘working’ on the data delivery backend before you can effectively design the visual elements, otherwise you’ll be trying to work with empty ListBoxes and DataGrids etc. In order to solve this problem, I have designed a base collection class that automatically generates test data in debug builds, but loses all of that redundant functionality for efficiency and security in release builds. Without further ado – here is the code for the base class I am using for my data collections (explanations follow)   public class CollectionBase<T> : ObservableCollection<T> { private static readonly Random rand = new Rand... [More]

Tags: ,

Silverlight

Silverlight ‘Loading’ Spin Icon in XAML

by Dean 18. January 2009 15:36
When loading large object collections in Silverlight, there is enough of a time delay so that I need some kind of animated icon that indicates a ‘loading’ state. There were many such icons used when loading data via AJAX, which are basically animated Gif’s. As Gif’s aren't supported in Silverlight, I needed to create one. I decided therefore to create a design in Expression Design, and then animate it in Blend, with a little tidying up in VS2008. Im not sure how well it’ll perform with large number of instances in a single control, but it does the trick for my needs. The code for my animated spinning logo is below. (Use the scaletransform in the grid to change the size) <Grid x:Name="LayoutRoot" Background="White"> <Grid.RenderTransform> <ScaleTransform x:Name="SpinnerScale" ScaleX="0.5" ScaleY="0.5" /> </Grid.RenderTransform> <Canvas RenderTransformOrigin... [More]

Tags: ,

Silverlight

Coming Soon

by Dean 17. January 2009 16:19
This blog is under construction and will be coming soon

Tags:

Most comments

Eric Eric
1 comments
us United States
Tom Tom
1 comments
Derek Lakin Derek Lakin
1 comments
gb United Kingdom
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 ButtonChrome.com