Category Archive: DotNet


Filtering Microsoft Surface Finger Touches for ScatterViewItems

By default, Microsoft Surface responds to any touch, including non-finger touches for example caused by a hovering hand or a sleeve touching the table. While they can be ignored using the GetIsFingerRecognized() method and setting the Handled flag of TouchEventArgs in preview touch handlers, the ScatterView seems to be somewhat special. Although you cannot move it ScatterViewItems …

Continue reading »


.NET/C# Prism InteractionRequests in WPF

Using Prism’s InteractionRequests, view models can make interaction requests (such as notifications or confirmations) to the view. It seems that WPF support and documentation lacks behind Silverlight, though. Therefore, I compiled a quick example using InteractionRequests in WPF to trigger a message. View Model using Microsoft.Practices.Prism.ViewModel; using Microsoft.Practices.Prism.Interactivity.InteractionRequest;   public class MyViewModel : NotificationObject { …

Continue reading »


.NET/C# First Visible Item (ListBox) Attached Behavior

I improved and refactored my previous code to get and set a ListBox’s first visible item. It is now realized as attached behavior and supports two-way binding: ListBoxExtensions ListBoxExtensions adds some methods to the ListBox class to get and set its first visible item. It expects the ListBox to use a VirtualizingStackPanel to hold its …

Continue reading »


.NET/C# Binding Custom DependencyProperty to ViewModel Property

Consider the following scenario: UserControl with a custom DependencyProperty ViewModel with an exposed property (using INotifyPropertyChanged) Goal: create two-way data binding between these two properties (i.e., ViewModel property gets updated if DependencyProperty changes and vice versa) ViewModel (implements INotifyPropertyChanged): private string _someProperty;   public string SomeProperty { get { return _someProperty; } set { _someProperty …

Continue reading »


.NET/C# Get First Visible Item of a ListBox

This is some code to get the first visible item in a WPF ListBox whenever the user scrolled. In XAML: <ListBox Name="MyListBox" ItemsSource="{Binding SomeCollection}" ScrollViewer.ScrollChanged="ScrollChanged"/> In the code-behind: private void ScrollChanged(object sender, ScrollChangedEventArgs e) { VirtualizingStackPanel panel = FindVisualChild<VirtualizingStackPanel>(MyListBox); if (MyListBox.Items.Count > 0 && Panel != null) { int offset = (panel.Orientation == Orientation.Horizontal) ? …

Continue reading »


.NET/C# MVVM RelayCommand with Parameters

I am using the MVVM Light Toolkit here to implement a RelayCommand with parameters. In this example, the command adds a value (entered by the user) to a number (held in the view model). A TextBox is used to enter the value. I did not like the idea of binding its value to a property …

Continue reading »


Windows Phone 7: Callbacks and Duplex WCF

WP7 Communication (General Callback)

As Windows Phone 7 (WP7) does not seem to support application-level sockets at the moment I was looking into using WCF to implement a simple client-server application. Further, my application required messages to be sent in both directions. Think of a chat application for example where messages need to be sent  from client to server as …

Continue reading »


.NET/C# TUIO Server

There only seems to be a C++ implementation of the TUIO server, not a C# version yet. I quickly looked into writing a C# wrapper, but it seemed to be rather complicated. Using Bespoke’s Open Sound Control (OSC) library, I started implementing my own C# TUIO server. It is still quite limited (only support external TUIO cursors …

Continue reading »


.NET/C#/WPF Create WPF Window from Non-WPF Application

Creating a WPF window from a non-WPF, standard Windows application: class Program { static void Main(string[] args) { Thread thread = new Thread(new ThreadStart(() => { // Create WPF window MainWindow window = new MainWindow(); window.Show();     System.Windows.Threading.Dispatcher.Run(); })) { IsBackground = true }; thread.SetApartmentState(ApartmentState.STA); thread.Start(); } } It seems that DynamicResource has to …

Continue reading »


.NET/C# CSV Export of Properties

Export an object’s properties as comma separated values (CSV) using reflection. public static string GetCsvHeaderString() { return String.Join(",", typeof(MyClass).GetProperties(). Where<PropertyInfo>(x => x.CanRead). Select<PropertyInfo, string> (x => x.Name).ToArray<string>()); }   public string ToCsvString() { return String.Join(",", GetType().GetProperties(). Where<PropertyInfo>(x => x.CanRead). Select<PropertyInfo, string> (x => String.Format("{0}", x.GetValue(this, null).ToString())).ToArray<string>()); } Tweet This Post Post to Facebook Send Gmail

Older posts «