Skip to main content

Posts

Showing posts from January, 2011

MVVM and the WP7 ApplicationBar

Last week, I spend some time trying to find the best way to use the WP7 ApplicationBar in an MVVM style way.  What makes this hard is that in the current version of the Windows Phone 7 Silverlight framework, it is not possible to attach any command on the ApplicationBarMenuItem and ApplicationBarButton controls. After trying multiple styles, I choose for the most pragmatic solution(with the risk that the MVVM police will come and arrest me). I simply invoke the command in the ViewModel from the codebehind. In the XAML I register for the Click event: <shell:ApplicationBarIconButton Text="Refresh" Click="Refresh_Click" IconUri="/Resources/appbar.refresh.png"/> And in the code behind I invoke the command: private void Refresh_Click(object sender, EventArgs e) { var vm = DataContext as EventsViewModel; if (vm != null) { vm.RefreshCommand.Execute(null); } } I know that it is less elegant than using attached behavi

Async updates of Windows Forms controls

Derick Bailey published this nice extension method to simplify the invokation of  Windows Forms controls outside the UI thread. public static class ControlExtensions { public static void Do<TControl>(this TControl control, Action<TControl> action) where TControl: Control { if (control.InvokeRequired) control.Invoke(action, control); else action(control); } } It's a simple extension method that allows any UI control to update itself when called from an asynchronous method - whether it's running from a .BeginInvoke() call, a BackgroundWorker , a ThreadPool thread, or any other form of asynchronous call. Simple, clean and useful. Thanks Derick!

10 jQuery tips to make your site go faster

  While searching for some best practices about jQuery usage, I stumbled over the following blog post with 10 tips to make your jQuery site go even faster: http://csharptutorial.blogspot.com/2010/12/10-tricks-that-will-make-your-jquery.html .

TFS 2010: Setting Remaining work to 0

Last week, I got a customer request to update the "Remaining Work" field and set it to 0 when the work item is resolved. Doing this can easily be done by altering the work item type definition. First of all make sure that you have the Team Foundation Server Power Tools installed. Open Visual Studio 2010. Go to Tools –> Process Editor –>Work Item Types  --> Open WIT From Server. Select the Team Project and Work Item Type you want to open. The Work Item Type Editor is loaded. Go to the workflow tab and click on the desired transition. The Workflow Transition window is loaded.   Go to the Fields tab. Add a field reference to "Microsoft.VSTS.Scheduling.RemainingWork" Add a new rule of type "COPY" Choose From = "value" and enter value = "0"

TFS Error while downloading files to workspace: The server returned content type text/html, which is not supported.

Last week, one of my clients reported me the following error while downloading a branch in a new workspace: C:\Source Control\ProjectName\03 Releases\2.0.3828\ProjectName.Business\Logic\Reservation\Calculations\CalculateDataR1BL.cs: The server returned content type text/html, which is not supported. After investigation we came to this post and execute the proposed SQL script on the TFS database as shown in the attached screenshot. This problem can happen if you upgraded from TFS 2008/2005. If the sql query returns more than 0 rows, you are indeed affected by the problem. Luckily a hot fix is available(KB Article Number : 2434700 ). Contact Microsoft Support to get a link to the download location.

Caliburn.Micro at VISUG

On Tuesday, February 08, 2011 I’m doing a session about Caliburn.Micro for the Visual Studio User group in Belgium. You've heard a lot about Model-View-ViewModel (MVVM), but you've struggled to see how it can help you in your day-to-day work. Or, you're experienced at implementing MVVM, but looking for some ways to maximize your investment in this methodology. In this session, we explore Caliburn.Micro( http://caliburnmicro.codeplex.com/ ), a simple MVVM framework, by iteratively identifying pain points in our UI development and eliminating them with simple solutions. You'll walk away with code, but more importantly with an understanding of how to apply some simple ideas to improve productivity with MVVM in your own projects. Be there!

TFS Administration Tool for TFS 2010

After a very long waiting time,  there is finally a new version of the TFS Administration Tool available. You can download it from the TFS Administration Tool project website. This release is the first version of the TFS Administration Tool which is built on top of the Team Foundation Server 2010 object model. Note: Before installing the TFS Administration Tool 2.1 please make sure that you have removed the previous versions of the tool from your machine and that you either Team Explorer 2010 or Team Foundation Server 2010 installed. If you don’t know the TFS Administration tool, in short it allows Team Foundation Server administrators to manage user permissions on all three platforms utilized by Team Foundation Server: Team Foundation Server, SharePoint, and SQL Server Reporting Services. The tool also allows administrators to easily copy user permissions among team projects and to easily identify any missing permissions on any of the three platforms. A must have for all TFS a

Azure Durable Message Buffers

Last year at PDC 2010, the Azure AppFabric team made a number of important announcements. One of the improvements they released was a significantly enhanced version of the Azure AppFabric Service Bus Message Buffers feature. What’s the difference between the current Message Buffers and the new Durable Message Buffers? The current version of Message Buffers provide a small in-memory store inside the Azure Service Bus where up to 50 messages no larger than 64KB can be stored for up to ten minutes. Each message can be retrieved by a single receiver. This makes the range of scenario’s where this is useful somewhat limited. The new version of Message Buffers enhance this feature so it could have a much wider appeal. Message Buffers are now durable and look much more like a queuing system. This makes it possible to start using Durable Message Buffers as an alternative to the Azure Queues.

WPF: Creating a borderless window

For a new application we are building we want to have a completely different look for the windows in our application. Therefore we wish to eliminate the border to give it a custom look. Doing this in WPF is easy. To get a border-less window, you need to set the following attributes on your Window. WindowStyle="None" AllowsTransparency="True" Background="Transparent" The WindowStyle attribute normally allows you to set a single border, three-D border, or a Tool Window border. Setting this attribute to None will eliminate the border. The next two attributes, AllowsTransparency and Background work together. You must set AllowsTransparency to True to allow the Background to be set to Transparent.

Windows Phone 7: Setting the start page

By default when you create a Windows Phone 7 application, a start page is created for you. But what if you want to change this later on to a different page? We need a way to specify which page should be used as start page. All that we need now is to change the startpage from MainPage.xaml to newstartpage.xaml . Expand the Properties folder of the WP7 C# Project and Open the WMAppManifest.xml This file keeps track of things that belongs to the Application . The important property here is the DefaultTask. Change the NavigationPage to the page you want to use as start page .

Windows Phone 7: Simplify URL typing

When the user places the focus on to the textbox, in the Windows Phone 7, the default keyboard / onscreen keyboard will pop up for the user to touch and type the characters to the textbox. It is also important that the keyboard can be customized depending on the input the user will be typing or the data type the textbox is associated with. For an application we are building the user has to specify a URL. By specifying an input scope , we can change the layout of the Keyboard.  This will help the end user to easily type the required characters even faster. Setting the Input Scope is very simple and is demonstrated below.The sample Application contains a simple textbox (textBox1) with a title. When the focus comes to the textbox, the default onscreen keyboard will be displayed as shown below. If we want to change this to speed up url writing, add an event handler to the page loaded event and insert the following code: InputScope Keyboard = new InputScope(); InputScopeName ScopeName = n

Windows Phone 7: Detecting the WP7 Theme

The Windows Phone 7 comes with two background color modes dark or light. The easiest way to identify the Theme that the user has choosen in the device can be found via the Application Resources . In the Development Environment , you can find the file ThemeResources.xaml in the path C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Design The easiest way to find if the Dark or Light Background is visible is again by using the Resources string PhoneLightThemeVisibility or PhoneDarkThemeVisibility which will give you information if visible or collapsed . You can encapsulate this logic in your own class and use it throughout your application. 1: public class Settings 2: { 3: public static Settings Instance = new Settings(); 4:   5: private Settings() 6: { 7: } 8:   9: public Theme CurrentTheme 10: { 11: get { return (Visibility)Application.Current.Resources[ "PhoneLig

Windows Phone 7: Setting the Tile image

On a Windows Phone 7 people can pin your application to their start screen. To pin an app, you hold down until you get the menu below, then you pin it to the start screen. After you do this, you’ll see a big icon box with your application name. The icon that is shown in the Tile can be set in the project’s properties page… But although I changed the Background image to another png, it didn’t show up inside the Tile. I found out that I didn’t see my image because I had set the Build Action for my PNG file to Resource instead of Content. Adding it defaults to Resource, but for the purposes of the Pin-To-Start tile image, you just need to switch it to Content instead. Still strange that I was able to pick it from the Background image list…

Windows Phone 7: Detect device type

The Windows Phone 7 Emulator is a great way to test your applications before deploying them. However there are obvious limitations, such as working against the GPS system where the emulator just can’t quite cut it. In those situations it is common to create some sort of simulation to mimic the desired behavior. But once you have deployed your application to a real device you do not want your simulation routines to execute. Fortunately you can check for the DeviceType and avoid calling any emulator specific code you may have embedded. Checking For the WP7 Device Type The System.Devices.Environment.DeviceType property returns either DeviceType.Device or DeviceType.Emulator indicating what platform the application is running. Notice that reading the Microsoft.Devices.Environment.DeviceType property generates garbage, causing garbage collections when you don't want them.  Therefore it’s better to call it once at the start of your app and save the value. Here is a simple example how yo

Razor Syntax Quick Reference

With the release of ASP.NET MVC 3 and WebMatrix 1.0 you get the new Razor syntax for your views. Although Intellisense helps you a lot, some extra guidance for the Razor syntax can be useful. It turns out, there is a pretty good guide about Razor available, but it’s focused on covering the basics of web programming using Razor and inline pages and not just the Razor syntax. If you are looking for a concise quick reference about the Razor syntax, check out Phil Haack’s blog .

Icons for your Windows Phone 7 app

Looking for some nice icons to use inside your Windows Phone 7 application? First have a look  at the Windows Phone 7 icon pack. This package contains a set of 64 app bar icons that you can use when developing applications for Windows Phone. In addition to the 64 icons in PNG format (32 dark and 32 light), this package also contains vector versions that can be easily imported into Microsoft Expression Blend. UPDATE: The Icon Pack is now part of Expressions Blend for Windows Phone. When you are working with the application bar and add items you can change the icon used using a drop down in Expressions Blend for Windows Phone. When you select an icon it is automatically added to your project. If you want to get to the icons to work with them yourself you can find them on your drive in C:\Program Files\Microsoft SDKs\Windows phone\v7.0\Icons. . Another option is this package created by  Bil Simber .  It contains 502 Metro style icons in PNG, XAML and the ori

Error while deploying to Windows Azure Devevelopment Fabric

At a customer, after installing the Windows Azure SDK version 1.3 , when we tried to deploy their app on the development fabric, Visual Studio throws us the following exception. System.ServiceModel.CommunicationObjectFaultedException was unhandled   Message=The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.   Source=mscorlib   StackTrace:     Server stack trace:        at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)     Exception rethrown at [0]:        at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)        at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)        at System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)        at System.ServiceModel.ClientBase`1.System.ServiceModel.ICommunicationObject.Close(TimeSpan timeout)        at Microsoft.WindowsAzure.Hosts.

Bug in WP7 Training kit

Last week I lost a lot of time while implementing push notifications for my Windows Phone 7 app(more about it soon!). I implemented the push notifications similar to thearrangement that Microsoft has set up in the WP7 training kit. When I launch the app and then exit the app to go back to the home screen, I am able to successfully send a toast notification. However, when I send the same exact shell toast notification to my application while the application is running in the foreground, I get an error complaining that there is an invalid character for the root XML node. I found out there is an error in the NotificationSenderUtility that comes with the WP7 push notification sample in the training kit to send the notifications. Anyway the solution is simple, replace the PrepareToastPayLoad message inside the NotificationSenderUtility with this code: 1: private byte [] PrepareToastPayload( string text1, string text2) 2: { 3: MemoryStream stream = new M

TF84032: Team Foundation could not insert the work item list.

Last week I upgraded my Office 2007 installation to Office 2010. After the installation was complete, the Team Foundation Server integration started failing. Everytime I tried to open a work item list in Excel, the following error message was returned: If I tried to open Excel from inside Visual Studio, another error was returned: On the Internet the following possible solutions were mentioned: Repairing the  Visual Studio Tools for Office Runtime. Didn’t help for me. Repairing the Microsoft Office 2010 installation. Didn’t help either Re-registering the TFSOfficeAdd-in.dll (regsvr32 "C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\TFSOfficeAdd-in.dll") Then I found some information on the MSDN forums about how to get extra tracing info: 1. Copy the following contents to a config file and name it as Excel.Exe.Config (for TFS Excel Add-In) or WinProj.exe.config (for TFS Project Add-in) <?xml version="1.0"?>

Writing a repository class

Persistence has been a hot topic in software development for a long time. The main problem is that the most popular approach for software development these days, Object-Orientation, doesn’t really map easily to efficient external storage systems like relational or even noSQL databases. The technical limitations were mostly solved with some object mapping tools(ORM) like NHibernate or Entity Framework that make persisting and querying objects a breeze for most scenarios. The problem then became how do we integrate the act of persisting and retrieving objects with our Domain Model and, more important, our Ubiquitous Language. A good way to integrate persistence needs and the Ubiquitous Language is using what is known as Repositories. In his Domain Driven Design book , Eric Evans defines the Repository pattern as “A mechanism for encapsulating storage, retrieval, and search behaviour which emulates a collection of objects” . Naming as a solution The concept of a Repository as a list of ob

Effective Windows PowerShell free ebook

A late Christmas gift for everyone,  Keith Hill has turned a set of blog posts into an 61 pages long PowerShell ebook. Download your own copy here .   Table of content: Introduction Item 1: Four Cmdlets that are the Keys to Discovery within PowerShell Key #1: Get-Command #2: Get-Help Key #3: Get-Member Key #4: Get-PSDrive PowerShell 2.0 Update Item 2: Understanding Output Output is Always a .NET Object Function Output Consists of Everything That Isn't Captured Other Types of Output That Can't Be Captured Item 3: Know What Objects Are Flowing Down the Pipeline Item 4: Output Cardinality - Scalars, Collections and Empty Sets - Oh My! Working with Scalars Working with Collections Working with Empty Sets Item 5: Use the Objects, Luke. Use the Objects! Item 6: Know Your Output Formatters Item 7: Understanding PowerShell Parsing Modes Item 8: Understanding