Blend Behaviors + DependencyPropertyDescriptor = Memory Leak

March 14, 2013

In the past couple of weeks, I was taking part in a focused effort to find and fix memory-related issues in one of my client's applications. In this post I want to write about a specific type of memory leak that I found more than once, which is related to Blend-behaviors. As an example, consider the following behavior: 1: public class MyMarginDependentBehavior : Behavior<FrameworkElement> 2: { 3: private readonly DependencyPropertyDescriptor...
no comments

Kona – The ViewModelLocator Class

January 26, 2013

In previous posts I mentioned how, by using the Binding markup extension, the view automatically resolves its bounded properties from a view model object that is stored in its DataContext property. How the view model ends up being referenced in the view's DataContext property was left to be some kind of magic. In this post I will talk about the component that is responsible for making this happen – the ViewModelLocator. Before diving into the details, let's re-set the context. We have a simple view model with a single property, named FirstName: ...
no comments

Kona – The BindableBase Class

January 20, 2013

In the previous post I mentioned that the view's bounded controls can be updated automatically when the view model's properties to which they are bounded changes, given that the view model raises a specific event. In this post I want to elaborate on that, and walk you through the relevant implementation in Kona. The INotifyPropertyChanged Interface To provide change notification to the view's data bound controls, the view model should implement the INotifyPropertyChanged interface, which contains a single event called PropertyChanged, and raise that event whenever a property changes. The following example shows how the PropertyChanged...
no comments

Kona – Commands

January 18, 2013

The first thing I will cover in the series about Kona is the good old DelegateCommand class, that all of the Prism veterans learned to respect. But first, a quick overview for those of you who never worked with commands before. Why do we need commands for? One of the corner stones of MVVM is clear separation of the view from the view model. Those two components should be as loosely coupled as possible and interact only by using binding. To accomplish this separation, the view model exposes it's data with properties, and the view presents and...
no comments

Kona – Windows 8 LOB Apps Design Guidelines

January 14, 2013

Kona is an on-going project from Microsoft's patterns & practices team that is intended to provide guidelines and best practices for creating maintainable, testable and extendable Windows Store LOB apps. Kona is to Windows Store apps what Prism is to traditional WPF applications. Like Prism, Kona's release will contain the library itself (currently named Kona.Infrastructure), and a reference implementation. The first release of Kona is scheduled for the end of Q1 2013, and will provide guidance for subjects such as application lifecycle management, search, navigation, live tiles, local data management, proper layering, validation and more. The complete feature...
no comments

Setting a WPF Window to be Always on Top

January 5, 2013

Some applications require that their main window will always be on top of all the other windows. Doing so in WPF is quite simple. In this post I will show how. In order for the window to be opened on top of all the other windows, set its Topmost property to True. Doing just that is not enough, because when the window will lose its focus, it will be placed behind the focused window. To keep the window top-most even after it loses its focus, add an EventTrigger to the window's LostFocus event, and set the Topmost property...
tags: , , ,
no comments

Automatic Properties are not Fields

December 28, 2012

Even though that the statement in the title is trivial, the fact that the syntax of automatic properties and fields is almost identical can sometimes make us forget that they are two different things. Take, for example, the following struct: 1: 2: public struct MyData 3: { 4: public int A; 5: public int...
tags: , ,
no comments

My Presentation at the Technion: Introduction to Windows 8

December 19, 2012

Today, I gave a talk about Windows 8 at the Technion, on behalf of Microsoft Israel. The presentation was part of Microsoft's collaboration with the academic community. That was a 101 presentation which was focused mainly on the new features of Windows 8, and on how app authors should use them to write better apps. I wrapped things up with a quick, hands-on, demonstration. One of the participants asked me how to remove unwanted app shortcuts from the All Apps screen. Here is a great blog post describing how to do it step by step. Last, but...
no comments

Compiler Error: Invalid Character in the Given Encoding

December 14, 2012

Recently, a colleague of mine received the above compilation error, together with hundreds of other, less helpful errors, when he tried to compile what seemed to be a perfectly fine XAML code. The problems started after he removed all the comments from the source files with a program that he created. The program simply loads the source file's content, removes the comments, and then writes the updated content back to the file. Here is a naive example to illustrate the problem: 1: public void ProcessFile(string path) ...
tags: , ,
no comments

InvalidOperationException Is Thrown by PlayToReceiver’s StartAsync Method

November 27, 2012

While I was playing around with the new Windows Store Play-To contract, I came across a strange exception when I used the PlayToReceiver class to register my app as a Play-To target. Here is the relevant code: 1: protected async override void OnNavigatedTo(NavigationEventArgs e) 2: { 3: if (m_playToReceiver != null) 4: return; ...
tags: , ,
no comments