Silverlight 4: New features overview (Part 5) – DataBinding improvements

Wednesday, November 18, 2009

Silverlight 4 introduces improvements in DataBinding. between the improvements are IDataErrorInfo support, ability to bind to DataObjects, StringFormat, TargetNullValue, FallbackValue support and many others. This post will show how to use StringFormat, TargetNullValue and FallbackValue while databinding. For show the new features I’ve created sample application –> it will display values bounded to number of DependencyProperties defined in code behind. In code behind I’ve created number of Dependency Properties to bind to: public DateTime DateValue { get { return (DateTime)GetValue(DateValueProperty); } set { SetValue(DateValueProperty, value); } } // Using a DependencyProperty as the...

Silverlight Quick Tip: Dynamically Displaying Class Fields/Properties

Thursday, August 13, 2009

In one of my projects I had to create something like Visual Studio property window, for data set of different controls/data classes. Those controls/classes are still under development and I needed the way to display/change values of those properties dynamically without even knowing what is inside. For the simple case, let’s assume the following class which holds the data: public class SampleData { public SampleData() { BooleanProperty = false; } public string StringProperty { get; set; } public bool BooleanProperty { get; set; } public Button ButtonProperty { get;...

Silverlight Quick Tip: Resources in RESX files – Image Resources for Localization

Tuesday, July 14, 2009

This post was actually born in the middle of previous post :) I had to find the way to use images as a RESX resources – this actually was second question of the person who asked me about forcing the rebinding. Before starting, some theory about RESX usage in Silverlight. Silverlight support usage of RESX files and localization via “SupportedCultures” attribute in CSPROJ file. The attribute itself even exists in project created with Silverlight 3  Tools, but for some reason there is no interface to change the cultures (or at least I didn’t found them). So the only way (for me) to...

Silverlight Quick Tip: How to force re-binding

Today I’ll show how to do “dirty trick” to force re-binding and as a result UI value updating. First of all – the reasonable question – “Why force rebinding? Why not use INotifyPropertyChanged mechanism?” This was my questions also, but the person who asked the question had his reasons: he is using resources (Resx) to localize the application and bind the UI to those resources. Also UI gives user an ability to change the language (and code behind  does it by changing CurrentThread.CurrentUICulture). In this case what should be the notification? The request was to keep binding definition...

Quick Tip: LINQ & Data Binding notifications

Tuesday, June 23, 2009

In Silverlight & WPF we could databind to the LINQ query results: private ObservableCollection<string> someData = new ObservableCollection<string>(); //Somewhere in code someData.Add("Alex"); someData.Add("Alen"); someData.Add("Josh"); someData.Add("Brad"); var res = from data in someData            where data.StartsWith("A")            select data; listbox.ItemsSource = res; ”listbox” is the name of the Listbox on my XAML page. When application will load we will get expected results: But what happens when out collection (reminder: ObservableCollection, which implements INotifyCollectionChanged) changed? someData.Add("Antony"); Nothing! Because we bounded to the LINQ query (predicate), and the query was executed...

Silverlight 3 Quick Tip #9: DataBinding with Validation

Sunday, June 21, 2009

Silverlight 3 provides validation mechanism while using Two-Way data binding. Silverlight 3 also provides default a Validation Exception UI – callout with exception details, which could be customized. Many input-related controls such as TextBox, CheckBox, etc. have built-in support for validation. How to use? Simple, like everything with Silverlight: To enable validation, use the ValidatesOnExceptions property. <TextBox Text="{Binding ID, Mode=TwoWay, ValidatesOnExceptions=True}" /> //Code behind – property definitionpublic string ID { get { return id; } ...

What’s new in Silverlight 3 Beta 1?

Wednesday, March 18, 2009

As just announced at MIX09 keynotes, new version of Silverlight will hit our machines – this time it will be Silverlight 3 Beta 1. Here is the short list of what’s new in there: Go offline with your application: Silverlight 3 provides all the features you need to store your application on your users machine, and then work against their data in the your isolated cache or under their MyDocuments. Your application can ask the user if they want to add a link to your application on their desktop or start menu. In addition, you can check...

Silverlight 2 Metro Training Event in Mumbai

Thursday, February 26, 2009

I’m doing a Silverlight 2 Training for MS Metro program in Mumbai. Thanks for all participants in this event. Hope you enjoyed the course as much as I enjoyed doing it. As promised the selected samples from this event could be found here. Samples updated…   Thanks and Enjoy the samples Alex

Quick Silverlight Tips: Control Reflection, Control Properties Data Binding, Window Title and Status Bar text (IE only)

Monday, December 1, 2008

Well it was pretty long time since my last post here… I was busy, mostly doing consulting… Now the pressure is eased of alittle, so I hope to write here more.   During this time I heard a couple of questions from clients which were pretty easy to solve but possibly still not obvious. My first tip today will be about “how to produce reflection under text box” and “emulate PropertyBinding” (like it worked at WPF) To produce reflection (in case of TextBox) I built Vertical StackPanel with desired TextBox and TextBlock with applied ScaleTransform....