Windows 7: RTM in English will be available soon

Over the last days, there have been many rumors surrounding RTM of Windows 7. The 13th July was expected to be the official date when Microsoft will present the RTM at the partner conference (WPC), but it wasn't. On that date Microsoft said that they were close to RTM, but hadn't finished yet. The second half of July was then expected to be the timespan when Microsoft will announce RTM of Windows 7. Yesterday Microsoft came up with the promised information to the dates of Windows 7. The information was posted on the windows team blog. For developers windows 7 RTM will be available in English on 7th August. Find the blog-Entry with more dates for Partners, Consumers etc. here: http://windowsteamblog.com/blogs/windows7/archive/2009/07/21/when-will-you-get-windows-7-rtm.aspx I'm looking forward to switch to RTM and kicking my (really well running) RC away. Cheers Thomas
Read more...

Here it is: The UpdateSourceTrigger for PropertyChanged in Silverlight

Today I'll show you how to implement a PropertyChanged-UpdateSourceTrigger for Silverlight. In Silverlight a Data Binding can have different UpdateSourceTriggers. An UpdateSourceTrigger specifies, when a TwoWay-DataBinding will update its source with the value of the Target-Property.

In most cases you have a TwoWay-DataBinding on TextBoxes. When the user types something into a TextBox, it should be written back to the underlying Data-Object. The other way, when the underlying Data-Object changes, the TextBox should show the actual value of the bound property.

In this post I'll focus on the moment of writing the data back to the underlying object. In other words, when the data is updated with the text the user has typed in.

In Silverlight the underlying object is updated after the TextBox has lost its focus. In WPF, the UpdateSourceTrigger-Enum has a Member PropertyChanged. If you set the UpdateSourceTrigger-Property of the Data Binding to that value, the underlying object will be updated everytime the user changes the text. Unfortunately Silverlight doesn't contain the PropertyChanged-Value in its UpdateSourceTrigger-Enum. It only contains a Default- and a LostFocus-Member. As the name implies, LostFocus will update the source when the TextBox loses its focus. But an Attached Property would do the trick.

When I tried to solve this problem I came across a post of Michael Sync, who showed up a solution with an attached-Property that works by stealing the focus everytime the Text of a TextBox changes, and immediately set it back to the TextBox again. Find his post under http://michaelsync.net/2009/06/10/silverlight-attached-properties-bindingupdatesourcetriggerpropertychanged

As I got deep knowledge about WPFs Binding-Engine, I could produce a solution for Silverlight, and I think I got a similar solution to Michael's, but my solution is built closer on the binding-engine and doesn't need a focus-trick. So, some details: Behind each Binding, a BindingExpression does the real work. All you have to do when the Text of the TextBox changes is to get the BindingExpression of the Data Binding and to call its UpdateSource-Method. So my Attached-Property-Class looks like the one below (Feel free to use the source in your projects, but please keep the reference to www.thomasclaudiushuber.com). As it is, it just works for the Text-Property of TextBoxes.

/// <summary>
/// Supports a PropertyChanged-Trigger for DataBindings 
/// in Silverlight. Works just for TextBoxes
/// (C) Thomas Claudius Huber 2009
/// http://www.thomasclaudiushuber.com
/// </summary>
public class BindingHelper
{
  public static bool GetUpdateSourceOnChange
    (DependencyObject obj)
  {
    return (bool)obj.GetValue(UpdateSourceOnChangeProperty);
  }

  public static void SetUpdateSourceOnChange
    (DependencyObject obj, bool value)
  {
    obj.SetValue(UpdateSourceOnChangeProperty, value);
  }

  // Using a DependencyProperty as the backing store for ...
  public static readonly DependencyProperty 
    UpdateSourceOnChangeProperty =
      DependencyProperty.RegisterAttached(
      "UpdateSourceOnChange",
      typeof(bool),
      typeof(BindingHelper),
      new PropertyMetadata(false, OnPropertyChanged));

  private static void OnPropertyChanged
    (DependencyObject obj,
    DependencyPropertyChangedEventArgs e)
  {
    var txt = obj as TextBox;
    if (txt == null)
      return;
    if((bool)e.NewValue)
    {
      txt.TextChanged += OnTextChanged;
    }
    else
    {
      txt.TextChanged -= OnTextChanged;
    }
  }
  static void OnTextChanged(object sender,
    TextChangedEventArgs e)
  {
    var txt = sender as TextBox; 
    if(txt==null)
      return;
    var be = txt.GetBindingExpression(TextBox.TextProperty);
    if (be != null)
    {
      be.UpdateSource();
    }
  }
}

The usage of the BindingHelper-class is very simple. Just add it to your project, insert a matching xmlns to your XAML file that contains the CLR-Namespace the BindingHelper-class is in. When that is done, you can simply set the UpdateSourceOnChange-Property on a TextBox to true, and if the Text-Property is databound, you'll have a Data Binding that will update its source on every PropertyChange. Like in WPF. :-)

<UserControl ...
    xmlns:local="clr-namespace:BindingHelperExample">
  <Grid x:Name="LayoutRoot">
      ...
    <TextBox Text="{Binding FirstName, Mode=TwoWay}" 
    local:BindingHelper.UpdateSourceOnChange="True" />
      ...
    </Grid>
</UserControl>

If this post helped you, please kick it. :-) kick it on DotNetKicks.com
Read more...

Silverlight 3 and Expression Blend 3 are now avaibable

So I know, I've been really quiet for some time. There are many things going one. Currently I'm writing some articles (at least 6) for the German dotnet-magazine. Also I'm writing on a new book to Silverlight 3, and the timeline is very strict. That's the reason why there is not as much time for blogging, but I'll do better in the future. :-) So, Silverlight 3 and Expression Blend 3 are just out, and this time I try to be faster than Tobias, the www.nextbestgeek.com  (even if he showed me the fastest way how to find the downloads). So find the downloads here: Expression Blend 3 with Sketchflow Silverlight 3 Software Development Kit (SDK) Silverlight 3 Tools for Visual Studio 2008 SP 1 Cheers thomas: PS: And next week I'll show you how to support a PropertyChanged-UpdateSourceTrigger for Data Bindings in TextBoxes in Silverlight
Read more...