C#

Exploring NuGet

Since 5 hours now, I ‘m on NuGet and I’d like to share my first experiences. Why did I join NuGet? I joined NuGet, because it seems to be the most comfortable way to share libraries, containing XAML controls. Share them between my own projects, as well as with you. Previously I always had to include the project containing the controls in the solution I was working on, which was really annoying.. How can you use it? Let’s assume that you want to use a package in your project. All you need is the NuGet Package Manager Visual Studio extension. You can install it via Tools/Extensions and Updates. To use/reference a package from NuGet right-click on the references in the solution explorer and select ‘Manage NuGet Packages’. Then you can search for the package you desire (for example ‘TCD.Serialization’) and add it to your project. How do I use it?…

C#

Draw the Skeletons in two lines

Hello, Recently I was coding some Kinect stuff and wanted to draw the skeleton that the user can see what’s going on. In the Samples there’s some code for that, but it’s pretty annoying to copy/paste it in your own project every time, so I wrapped it up in a class called SkeletonPainter. To use it you just need an Image of either 640×480 or 320×240 and hand it over to the SkeletonPainter, along with the resolution and a background Brush of your choice: SkeletonPainter painter = new SkeletonPainter(skeletonImage, SkeletonPainterResolution.Resolution320x240, Brushes.White); Of course, you need to hand him the KinectSensor as well: painter.SwitchSensor(sensor); This way you can easily switch the KinectSensor while the painter is still active^ Have a try and tell me what you think =) Download TCD.Kinect.zip

C#

Async CustomMessageBox on Windows Phone

UPDATE: There’s a new Version with .NET4.5 Support, Code Samples Hey there, As you may know, there’s just a limited set of MessageBoxButtons available in Silverlight for WP. However, you can make your own MessageBox in your Silverlight app using the Microsoft.Xna.Framework.GamerServices namespace as explained in this tutorial by Den Delimarsky. This method uses the old style async, which really sucks, so I decided to go the cool and smart new async way. You need Visual Studio Async CTP and Visual Studio 2010 to do this. The trick is to wrap the old async methods together with async Tasks, resulting in a Task<int> that shows the custom message box and returns the selected button in just one line: int result = await CustomMessageBox.ShowAsync(“Dinner time!”, “What do you prefer?”, 0, CustomMessageBoxIcon.Alert, “German”, “Italian”); Asynchronously and therefore non-UI-thread-blocking, of course If you’re interested you can have a look at the source: CustomMessageBox.cs…

Root

Sync specific Folders with SkyDrive

Some of you may know, that I’m a huge fan of Dropbox, Windows Live Mesh and SkyDrive alltogether. Each of them has some exclusive features that I find most useful. This is the public sharing using a single URL of Dropbox, the cross-platform Features of SkyDrive (WP7…) and the feature to ‘select and sync’ any folder on your hard drive with Windows Live Mesh (in contrast to the quite unflexible syncing of just one folder). Well today on reddit, I came across a link to a blogpost… This guy, Jan Hannemann, had a genious idea: In the NTFS file system you can hard-link folders in a way that and application (such as Windows Explorer, or Windows Live Mesh) thinks that the folder is really there. These links are called folder-junctions and can be created using the command line. Fortunately he created an extension to the Explorers context menu that lets you do this in just two…

C#

Save objects to the ‘LocalFolder’

IMPORTANT: You find the newest versions of TCD.Serialization on NuGet – it works with Windows Phone as well. This post will Show you how to serialize and save objects with XML to your apps LocalFolder/RoamingFolder. Metro style apps in Windows 8 have their own folders where they can store their data. These folders can be accessed by: StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFolder roamingFolder = ApplicationData.Current.RoamingFolder; The difference between these two folders is that Windows 8 will synchronise the RoamingFolder between different machines. This can be useful if you want to improve the user experience, for example by synchronising drafts of a blog post between a users tablet and PC. It’s very important, that the data you want to save is serializable. When designing the data structure and classes for your data, you got to make sure, that each class has a parameterless constructor. Properties can be marked with a set…

Metro

Column-Styled GridView

Today I had to figure out a way to make a single-row, column-styled GridView that looked like this: Some minor design improvements are still to be made, but the hardest part is done. Particulary tricky was, that the items didn’t want to Stretch the height. (I wanted to avoid hard-coding the height, because of different screen resolutions.) Finally I’m using a GridView – I archived almost the same results with a ListView, but the ScrollBar was gone.. Maybe this is possible with a ListBox as well, but maybe I want to integrate this with a SemanticZoom control later, which requires ListView or GridView. Here’s a screenshot of the XAML code: You can copy/paste the following: <GridView ItemsSource=”{Binding Mensen}” SelectionChanged=”GridView_SelectionChanged”>                 <GridView.ItemTemplate>                     <DataTemplate>                         <Grid Background=”Green” Width=”250″>                             <Grid.RowDefinitions>                                 <RowDefinition Height=”Auto” />                                 <RowDefinition Height=”*” />                             </Grid.RowDefinitions>                             <TextBlock Grid.Row=”0″ Text=”{Binding Titel}” Foreground=”{StaticResource ListViewItemOverlayForegroundThemeBrush}” Style=”{StaticResource TitleTextStyle}” Height=”60″ Margin=”15,0,15,0″…

C#

Migrating TCD to Windows 8 Release Preview

Two days ago, I migrated my laptop to Windows 8 Release Preview and today Windows Live Mesh finished syncing all of my files. So in the last few hours I migrated all the dev stuff and I’d like to share the latest versions of them too. Most of the libraries haven’t changed that much, only their namespaces have changed from TCD.Windows8.xxxx to TCD.xxxx. TCD.Serialization TCD.Serialization.Xml.XmlDeSerializer – (de)serialize an object from/to a string or Stream using XML TCD.Serialization.Json.JsonDeSerializer – (de)serialize an object from/to a string or Stream using JSON Download TCD.Serialization.zip TCD.Controls TCD.Controls.Flyout – create your own Flyout TCD.Controls.Settings.SettingsContractWrapper – integrate with the settings contract in just a few lines of code Download FlyoutAndSettingsSample.zip

C#

XML and JSON (De)Serialization in WinRT and Windows Phone

In some of my recent Metro/WinRT projects I had to save data to the disk. I decided to go for Xml-serialzation, because it’s human-readable, and flexible. Also it was perfect for the data I wanted to save (eg. metadata about a movie). (If you want to do it on your own: System.IO and System.Xml.Serialization are the namespaces you need for XML (de)serialization.) As I needed this in many projects, I composed a small library, containing a TCD.Serialization.XmlDeSerializer as well as a TCD.Serialization.JsonDeSerializer. Both have four static methods to serialize to/from Stream and string. You can download a package with the sources and a ready-to-use dll. TCD.Serialzation is available on NuGet it works with Windows Phone as well. NOTE: the methods aren’t fail-safe, so you might need to try{}catch{} them to handle exceptions. (For example if you want to serialize to a FileStream without write permission.) Have fun and let me hear…

C#

Performing long-running, timed operations on the UI thread

Recently I had to play timed sounds (morse code) in a WP7 applications. Sounds are required to be played on the UI thread, but as I had to time them, my UI thread got frozen. The reason was, that I used Thread.Sleep() to time the sound, which of course blocked the UI thread. Today I figured out a way to do this long-running operation (many seconds..) without blocking the UI thread. You may know the Visual Studio Async CTP – it’s required to do the trick. Let’s suppose we already have a method InvokeEvent() that plays the sound, changes a color or something like that. Currently we execute this method in a pattern like this, causing the UI thread to be blocked: void StartOperation()//invoke the event in a pattern { for (int i=0; i<20; i++)//20 times { InvokeEvent();//play the sound, blink with the display or something like that Thread.Sleep(500);//this will…

C#

Making a reverse Autocomplete-TextBox on Windows Phone

I’m sure you’re familiar with autocomplete textboxes and maybe you’ve even used them in a project yourself. They provide a fast and easy way for the user to select something, but they lack one important feature: they don’t show what could be selected. ReverseAutocompletePopup is a mixture between an autocomplete text box and the kind of popup you get when a ComboBox has more than five items. At first it displays all options in a ListBox and as you type non-matching ones are filtered out. (And brought back when you delete the text!) EDIT: In the newer version, the user can hit Enter to select, or optionally use his input as the result. When working with it there’re a few things you need to have in mind: The Popup control is no real navigation-thing, so you are in charge to handle OnBackKeyPress according to the guidelines! The Options for the…