Category Archives: .Net

Windows Phone vNext & Windows 8 next week

Update 26th 7:37PM: Nokia keynote live tomorrow morning at 8:30 CET. Live webcast here: http://www.nokia.com/global/about-nokia/webcast-mwc/webcast/

The coming week should be pretty interesting for any folks interested in Microsoft technologies. The Mobile World Congress will take place in Barcelona from Monday to Friday.

Windows Phone

On the mobile space, we can expect first official information about Windows Phone Tango. Tango is expected to be a version of the OS dedicated to low-end devices. From the various leaks that occurred in the last weeks we already have some ideas of what Tango might look likes:

  • ability to import and export contacts directly from the SIM card
  • ability to send multiple images in a single MMS
  • more languages supported (120, whereas Mango supports “only” 35)
  • ability to run on devices with only 256MB or RAM
None of those information have been confirmed yet but it’s only a matter of hours now 🙂
Of course in the Windows Phone world, the next big step will be Apollo. Apollo is expected to be the next major version of the Windows Phone platform. At this point, we don’t know if Microsoft is going to talk about Apollo during MWC.
After a leak about Apollo, Paul Thurrot wrote an article describing various aspects of this new version. Here are some expected features:
  • support for multi-core processors, new screen resolutions & NFC support
  • shared components with Windows 8 (this brings a lot of question: are we talking about WinRT for example ?)
  • app-to-app communication (similar to what is available in Windows 8 )
  • IE10
  • SkyDrive & Skype integration
Again, none of those information have been confirmed yet. We will see if MWC brings more answers.

Windows 8

On wednesday 29th Microsoft will hold a special event in Barcelona for the release of Windows 8 Consumer Preview.

The Consumer Preview will be available for download to anybody and should be feature complete. I’m expecting a lot from this release as the Developer Preview was quite incomplete regarding XAML development (for example Blend was only able to target HTML WinRT projects).

Visual Studio 11

With the release of Windows 8 Consumer Preview, Microsoft confirmed this week that we are also going to have access to Visual Studio 11.

Visual Studio 11 will include most of the extensions currently available in the Productivity Power Tools for Visual Studio 2010. The XAML designer will be shared with Blend (hopefully that we will to better performance & less design-time issues). There are tons of other changes, improvements and new features…

For more details, you can check out those posts: Introducing the new developer experience part 1 & part 2.

Of course I’ll try to play with all those new toys as soon as possible. So you should expect more blog post this week !

 

Windows Phone performance analysis & optimization during TechDays

In about 2 weeks now, I’ll have the chance to be part of the French TechDays in Paris as a speaker. This year, I’ll own a session called “Windows Phone performance analysis & optimisation” with my colleague Charlotte.

The agenda looks like the following:

  • why performance analysis ?
  • device vs emulator
  • leveraging WP7 threads
  • using the VS profiler for WP7
  • tips and tricks

During the session we will use a “real” app we’re working on for a few months now (I’ll share more details after the session). We have some cool tips that haven’t been shared anywhere before, so if performance is a topic of interest for you, stat tuned !

Click on the following image for a link to the TechDays website:

I’m planning to share the most of the content of this session on my blog soon after the event.

Don’t hesitate to stop by and say hi…

WPF databinding trick (part 2)

Ok, let’s see another strange behavior that you might have already seen with the WPF databinding engine.

INotifyPropertyChanged

When we teach WPF to new developers, at some point we need to introduce the INotifyPropertyChanged interface. Usually, the kind of speech which is given looks like this one:

When you’re doing a binding to a standard CLR property, you must add some kind of notification mechanisms in order to tell the binding when the value changes. In WPF, this is standardized by using the common INotifyPropertyChanged interface. This interface contains a single event which must be raised with the name of the property which has changed. Whenever this event is fired, the databinding engine is able to see the change and update the corresponding binding.

Demo application

Nothing really exciting here, right. Now, you start to do a demo with the following code:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        this.DataContext = new DataObject() { Data = "test " };
    }
}

public class DataObject
{
    private string data;

    public string Data
    {
        get { return this.data; }
        set { this.data = value; }
    }
}

Here the DataObject class I use as DataContext does not implement INotifyPropertyChanged.Then I added some XAML in the MainWindow:


    
        
        
        
    

And the goal is to display 3 TextBoxes all databound to the same property. Now, we run the application, types some text in one of the TextBox and change the focus in order to update the binding. Most of us would expect to have the 2 other Textboxes with the old value: when the focus has been lost the new string value has been pushed into the Data property, but the other Textboxes have no way to detect this change.

Actually if you run this application, you’ll see all the Textboxes being updated That’s strange…

Why does it works ?

Ok, let’s get into the dirty details. Here are what happens during initialization:

  • XAML is parsed
  • for the 3 TextBox
    • the Binding is initialized
    • a BindingExpression is created. The BindingExpression is a IWeakEventListener.
    • its AttachOverride method is called
    • if the UpdateOnLostFocus flag is set (which is the case because the default value of UpdateSourceTrigger is LostFocus), the static LostFocusEventManager type is used and the AddListener is called
      • during the initialization of the binding, the PropertyPathWorker class is added and at some point the ReplaceItem method gets called
      • then the following code gets execute
    if(source is INotifyPropertyChanged)
    {
    	PropertyChangedEventManager.AddListener(…);
    }
    else
    {
    	PropertyDescriptor descriptor = GetDescriptor(source, path);
    	ValueChangedEventManager.AddListener(…);
    }
    

    Which means:

    • if the source implements INotifyPropertyChanged, use that to track the changes to the property
    • otherwise, use the ValueChanged event of the cached PropertyDescriptor instance to track the changes

    What happens when one of the TextBox lost focus:

    • the focus changes to another control, the previously focused TextBox gets is LostFocus event raised
    • the LostFocusEventManager gets the notification
    • the notification is transferred to the BindingExpression (which is a IWeakEventListener) by calling the IWeakEventListener.ReceiveWeakEvent method
    • several method calls… ending in the PropertyPathWorker class where the PropertyDescriptor.SetValue methods is called (where the PropertyDescriptor is the one which has been cached during initialization)
    • this method raises the ValueChanged event at the PropertyDescriptor level
    • which is catched by the ValueChangedEventManager
    • and the associated dependency property (Text) is updated
    • and voila !

    So there are no miracle behind the demo application I was talking about, just the fact the binding engine is smart enough to cache the PropertyDescriptor used for setting value to CLR property and using the ValueChanged event to get notifications if the source does not implement INotifyPropertyChanged.

    Happy coding !