Quick introduction to Righthand.SharpRedux library

I've been experimenting with a redux implementation for .net lately and here is the current state.

The core library is quite functional and ready for a bit more serious test drive. There is also a visualizer, redux based, and with a frontend for WPF (other frontends can be added).

Available are two sample apps, Todo which is a WPF/MVVM/redux implementation of TodoMVC. And a dirty Playground sample.

Here are two screenshots from Todo sample and a brief introduction:

The application itself is on the left while visualizer is on the right. Visualizer is further composed of actions list and state|difference display. Above it shows current state after highlighted action. Value "[0] 1" in visualizer means list item with index 0 (when a list member) and item has an unique key with value 1 (when applicable).

Above the visualizer is showing state difference between the last action and previous one. You can also select any action from the list and click Reset to State which would rewind the state to one after that action.

But why would anybody bother with redux at all? The answer is logging, separation, unit testing and state rewind. Imagine you have an application that crashes - getting all the actions in proper order would give you the ability to reply exactly what user/application was doing until it crashed - even without any user intervention or feedback.

That's it for a quick introduction. I'll try to blog more, create more documentation about it, based also on feedback/interest. I'll try using it in a real project when an occasion appears. Also visualizer can be and probably will be improved. Right now is something that works well enough for start.

Righthand.SharpRedux is open source and hosted on github and libraries will appear soon on NuGet. You can also get the Todo sample as a zip (.net 4.6.2 required),

Immutable types are based on Righthand.Immutable which is also hosted on NuGet. Visual Studio 2017 extension that creates immutable code is available at Marketplace. Righthand.Immutable is optional for SharpRedux and can be used standalone.

About strongtyped datasets, DBNulls, WPF and binding

The mix of strongtyped datasets, DBNull values, WPF and bindings will likely yield exceptions of invalid cast type when binding nullable columns.

Imagine you have a table with a single, nullable, column Description. You would bind it against a TextBox (or any other control) with this syntax: {Binding Description}. When binding is performed against a row that has a DBNull value (remember, ADO.NET uses DBNull.Value for null values) in that column you get an Unable to cast object of type 'System.DBNull' to type 'System.String' exception.

The reason for that exception is quite simple. Let’s take a look at how ADO.NET implements the strongtyped Description column:

   1: [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
   2: [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "")]
   3: public bool IsDescriptionNull() {
   4:     return this.IsNull(this.tableXXX.DescriptionColumn);
   5: }
   7: [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
   8: [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "")]
   9: public string Description {
  10:     get {
  11:         try {
  12:             return ((string)(this[this.tableXXX.DescriptionColumn]));
  13:         }
  14:         catch (global::System.InvalidCastException e) {
  15:             throw new global::System.Data.StrongTypingException("The value for column \'Description\' in table \'XXX\' is DBNull.", e);
  16:         }
  17:     }
  18:     set {
  19:         this[this.tableXXX.DescriptionColumn] = value;
  20:     }
  21: }

The obvious problem is that WPF binding goes straight to Description property without checking IsDescriptionNull() method (as your code should) and then property getter fails to convert DBNull.Value to a string. And no, at this point even a converter won’t help you because the value is read before converter is even invoked.

But fear not, the solution is a very simple one. Just add square brackets around Description in binding syntax, like this: {Binding [Description]}. Looks similar but it is different. The former syntax uses strongtyped property to access the data while the later uses the DataRow’s this[string] accessor instead which returns an object and thus no exceptions are raised due to the DBNull.Value to string conversion. Furthermore a DBNullConverter value converter can come handy as well:

   1: public class DBNullConverter: IValueConverter
   2: {
   3:     public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
   4:     {
   5:         if (value == DBNull.Value)
   6:             return DependencyProperty.UnsetValue;
   7:         else
   8:             // return base.Convert(value, targetType, parameter, culture);
   9:             return value;
  10:     }
  12:     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  13:     {
  14:         if (value == null)
  15:             return DBNull.Value;
  16:         else
  17:             // return base.ConvertBack(value, targetType, parameter, culture);
  18:             return value;
  19:     }
  20: }

Multitouch development on Windows 7

I’ll be developing a multitouch application in WPF 4.0 running on Windows 7 and using Windows 7 native multitouch (supported in WPF 4.0) running in portrait mode. Dual finger touch should be enough. I have all the tools handy except for one: a multitouch input device aka multitouch monitor. So I am looking around for it and have found these options so far:

Bamboo Fun tablet

Last year I’ve bought a Bamboo Fun pen & touch tablet from Wacom. It supports both stylus and two finger touch input. I’ve assumed it will work natively with Windows 7. But it doesn’t. The core problem is that Bamboo has a relative touch positioning while Windows 7 requires absolute positioning – in other words Bamboo doesn’t know where your fingers are until you touch its surface. Furthermore Wacom decided to provide support through a generic driver to other OS beside Windows 7 and thus no Windows 7 native support is provided at this point in time. Disappointing.

Multitouch monitor

The most logical choice would be a multitouch enabled monitor. Heck, Windows 7 has been around for a while now (including beta and RC period) and there should be plenty of such monitors. At least that’s why I thought. Wrong again. There are some choices though. All of these supports Windows 7 native multitouch.

Acer T230H

A 23” 1920x1080 widescreen monitor from Acer. It supports dual touch through a some sort of simple mechanism using cameras. Has problems when you cross fingers or something like that. Not a huge problem in my case. But it has no pivot feature. I guess I’ll just put in horizontal portrait position on my desk or somewhere near. Despite these shortcomings this is my first choice at this point. The price tag is around 300€.

Dell SX2210T

A 21.5” 1920x1080 widescreen monitor from Dell. Smaller, slightly more expensive, dual-touch and no pivot as well.

Compaq L2105tm

The most hidden of the three. Similar to Dell’s one: 21.5” 1920x1080, no pivot. Couldn’t find it in EU so I am not sure about the price but in US is probably cheaper compared to Dell’s.

3M Multitouch developer kit

This one is interesting. A 19” 1440x900 monitor with support for up to 10 finger multi touch input. Looks like a perfect choice if it wasn’t for its price which is listed as $1.499 in US. I assume this is translated to >1.499€ for the EU. Ouch. Yet, this is the only multi-touch display that supports more than two fingers input.

Tablet PC

As an alternative to a proper monitor I might consider a tabled PC such as Dell Latitude XT2 or Acer AS5738PG-6306. First one is expensive and not exactly a development-grade fast machine, yet is a good quality product. The later is much cheaper and perhaps faster but has one fatal flaw in my case: the screen doesn’t rotate to “tablet” position and as such it won’t work in portrait mode. Furthermore touching the screen looks kind of problematic since you can easily flip it (imagine touching a standard laptop). Both laptops feature an integrated graphic card which isn’t good either.

A tablet PC is not the best option for my project anyway so I didn’t investigate much in this direction. The same goes for All-in-one multitouch PCs.

DIY alternative

Heh, I might even built a table like MS Surface by myself. Impossible? Not at all nor it is expensive. Actually it is very cheap. On the negative side it is quite time consuming, even more if you aren’t used to build such things.

Software simulation with multiple mice(MultitouchVista project)

There is way to simulate multitouch with multiple mice on normal monitor as well. Unfortunately it is not a feature of the OS but rather through a project hosted at CodePlex. Note that project has a Vista name in it, yet it runs under Windows 7 only – both x64 and x86. The idea is to trick OS to believe that mouse pointers are in reality fingers. This is done through a custom driver and a couple of services. I’ve tried to make it work with a single mouse to simulate panning and it worked on IE but not in my WPF 4.0 application for some reason. It was really a quick test and I should investigate why it isn’t working for my application further. But if I make it work this will be my way of doing multi touch until I get a proper multi touch monitor, possibly Acer T230H.


Obviously multitouch development requires either a very expensive full featured or a cheaper, but simplified and feature lacking hardware. If you don’t want to spend any money at all then you have to check the MultitouchVista project. If you are looking for a cheap dual touch monitor then Acer T230H sounds like a good choice.

Note that the hardware characteristics in this post aren’t based on real experience but rather on the data collected from internet.

If you have a different, or a better solution, or some real experience, please let me know.