Simple touch control using the display module

My background is in desktop UI programming using Windows Presentation Foundation. WPF is an amazing framework for creating highly responsive complex (or simple) desktop or Silverlight-hosted applications.  NETMF has a subset of WPF features which, for the most part, are easy to pick up of you have some WPF experience. A great reference for WPF is WPF Unleashed by Adam Nathan.

This demo shows some some basic functionality for NETMF using the Gadgeteer T35 Display. The demo shows a simple screen layout with touch responsive controls.  The controls trigger a multi color led module to display different colored lights.  It’s easy to envision using the touch panel to drive any type of event desired.

The result are well laid out controls with no absolute positioning. Avoiding absolute positioning is important for screens which are epxected to be responsive to orientation or the dynamic addition of other controls.

Simple WPF Touch Control

Setup for the example is the same as the MulitLED Queue example.

LED Queue Rotation Setup

WPF for NETMF doesn’t use XAML.  This is understandable giving the system contraints. Thus, you need to understand how WPF works.  For any WPF application, you must first create a Window.  The display module does that for you.  Setting the background color is done by applying a Brush to the Background property.  Then you need some way to add controls to the window.  A Window can only have one child element, so you the first control needs to be some type of “Container” which will accept other controls. For this example, I use a Panel.

Window window = display_T35.WPFWindow; window.Background = new SolidColorBrush(Color.Black); Panel p = new Panel(); window.Child = p;

The next step is to add a StackPanel which is a managed flow control. Basically, it controls the layout of other controls. For this example, I have a StackPanel which will layout and child controls vertically.

Next, I create a border elements for different colors

The GetBorder method simply create a rectangle with a specified colored background

Each border’s TouchDown event is wired to the MultiColorLed to turn a specific color. For the red:

The last part is to add a new horizontal stack panel containing a text label and the border element to the first stack panel. The GetStackPanel method creates a new StackPanel with a horizontal layout. Then it creates a new Text element, adds it to the stack panel. Lastly, it addes the border to the stack panel.

This solution can be found on my Gadgeteer GitHub repository.

Share this Post